nginx配置虚拟域名

修改host

  • host路径:C:\Windows\System32\drivers\etc\hosts
192.168.0.101 tomcat.paolu.com
  • 保存退出

创建nginx的配置服务

  • 进入nginx/conf目录下
    新建vhost文件创建tomcat.paolu.com.conf文件,内部输入
server { 
    listen 80; 
    autoindex off; 
    server_name tomcat.paolu.com; 
    access_log H:/access.log combined; 
    index index.html index.htm index.jsp index.php; 
    #error_page 404 /404.html; 
    if ( $query_string ~* ".*[\;'\<\>].*" ){ 
        return 404; 
    } 
    location / { 
        proxy_pass http://192.168.0.101:8080; 
        add_header Access-Control-Allow-Origin *; 
    } 
} 
  • 打开nginx目录下的nginx.conf文件,引入刚刚的vhost配置文件目录
 include vhost/*.conf;
example
  • 进入nginx目录下, 执行命令
 .\nginx.exe -t

输出:

nginx: the configuration file H:\nginx\nginx-1.10.2/conf/nginx.conf syntax is ok
nginx: configuration file H:\nginx\nginx-1.10.2/conf/nginx.conf test is successful

再执行

.\nginx.exe -s reload

打开tomcat.paolu.com即可访问到启动的端口为8080的tomcat服务页面。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容