nginx反向代理tomcat

2018-10-17  本文已影响0人  邝健强

环境介绍

在linux虚拟机下安装nginx和tomcat,在windows下通过浏览器访问

nginx配置

server {
        default_type 'text/html';
        charset utf-8;
        listen 80;
        autoindex on;
        server_name www.imooc.com;//注意这里
        access_log /usr/local/nginx/logs/access.log combined;
        index index.html index.htm index.jsp index.php;
        if ( $query_string ~* ".*[\;'\<\>].*" ){
          return 404;
        }
        location / {
         proxy_pass http://localhost:8080; //这里代理了虚拟机本地的8080端口
         add_header Access-Control-Allow-Origin *;
         }
}

注意:因为要访问虚拟机里面的nginx,所以要修改防火墙把80端口开放出去

修改host

192.168.80.128  www.imooc.com
192.168.80.128 image.imooc.com
192.168.80.128 s.imooc.com

192.168.80.128是我虚拟机的ip

192.168.80.128    www.imooc.com

效果

上一篇下一篇

猜你喜欢

热点阅读