nginx 配置去掉URL中工程名

作者: 陈俊飞 分类: Java,Linux 发布时间: 2017-07-12 18:15
    #通过域名访问特定tomcat项目并且隐藏工程名
    server {
        listen 80 ;
        server_name renrensecurity.yuanjilu.xyz;
        #index login.html index.html index.htm;#这个设置没用,要看项目自己的跳转
        location / {

                 proxy_set_header   Host             $host;#如果nginx是80服务,上面就够,代表默认servlet_port是80;否则需要Host $host:$server_port,不配置servlet_port会导致丢失端口
                 proxy_set_header   X-Real-IP        $remote_addr;
                 proxy_set_header   REMOTE-HOST      $remote_addr;
                 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                 proxy_cookie_path /renren-security /;#这个要放在proxy_pass上面
                 proxy_pass http://tomcat/renren-security/;
                 #proxy_pass http://renrensecurity.yuanjilu.xyz/renren-security/;
       }
       location /renren-security {

                 proxy_set_header   Host             $host;#如果nginx是80服务,上面就够,代表默认servlet_port是80;否则需要Host $host:$server_port,不配置servlet_port会导致丢失端口
                 proxy_set_header   X-Real-IP        $remote_addr;
                 proxy_set_header   REMOTE-HOST      $remote_addr;
                 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                 proxy_cookie_path /renren-security /;#这个要放在proxy_pass上面
                 proxy_pass http://tomcat/renren-security/;
       }

    }

效果展示http://renrensecurity.yuanjilu.xyz  admin admin