我原本项目访问路径是:
https://域名/项目名称/
需求是在上述路径不动的基础上,添加一个路径如下:
https://域名/A/项目名称/
方法是在443代理下添加如下:ipport、项目名称替换成自己的即可
location /A/projectName { proxy_pass http://127.0.0.1:80/项目名称; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; }
关键点是proxy_pass,当我设置成upstream server的时候无论怎么设置都无法正常工作。正常设置如下:
upstream myserver{ server 127.0.0.1:80; } location /naire2 { proxy_pass http://myserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; }