nginx根据项目名代理

应用场景,nginx代理服务器地址为:172.17.17.17:80

想通过 “172.17.17.17/solr”这个地址(实际请求地址为172.17.17.17:80/solr,http协议默认端口80可以省略) 代理到http://10.159.30.37:8080/solr这台机器的tomcat 项目上

nginx配置文件追加下面标红段落代码即可。

vim /nginx/conf/nginx.conf

-----------------------------------------------------------------------------------------------

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.html;
        }


        location /solr {
                 proxy_set_header Host $host;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 proxy_pass http://10.159.30.37:8080/solr;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


}

 

 

-------------------------------------------------------------------------------------

不要忘记返回sbin 检查 和reload

cd ../sbin/

./nginx -t

./nginx -s reload

你可能感兴趣的:(nginx,tomcat,java)