NGINX和TOMCAT配置动静分离端口丢失问题

xiaoxiao2021-02-27  203

nginx 外网端口2002, tomcat 只能内网访问对应nginx端口9001,其中tomcat js 及 statics目录为静态目录,其它的请求全部proxy到tomcat .

关键配置 proxyPort="2002" , 这个不加的话就会端口丢失,缺省访问到80端口去。

还有另为一种解决办法,利用 nginx , proxy_redirect 也可以。

proxy_redirect http://host http://host:2002;

tomcat配置如下:

   <Connector port="9001" proxyPort="2002" address="127.0.0.1" protocol="HTTP/1.1"                connectionTimeout="20000"                redirectPort="8443" />

nginx配置如下:

server {                 listen 2002;                 server_name www.xxx.com;                 # charset utf-8;                 # access_log  logs/host.access.log  main;                 location / {                         proxy_set_header Host $host;                         proxy_set_header X-Real-IP $remote_addr;                         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                         proxy_pass http://127.0.0.1:9001;                 }                 location ^~ /js/ {                         root /mnt/web/fswh-cms-admin2002/waproot;                         expires 24h;                 }                 location ^~ /statics/ {                         root /mnt/web/fswh-cms-admin2002/waproot;                         expires 15d;                 }         error_page 500 502 503 504 /50x.html;         location = /50x.html {                         root /html;         } }

转载请注明原文地址: https://www.6miu.com/read-10836.html

最新回复(0)