nginx 地址匹配规则
一、location 后面的url地址最后加/,和不加/的区别
location /xx-xxxx-xxx/api/xxxx/xxxx/ { proxy_pass http://xx.xx.xx.127:8766/xx/xx/; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; }
此处:/xx-xxxx-xxx/api/xxxx/xxxx/ 这个是全路径去匹配此匹配的全部删掉后,
重新用http://xx.xx.xxx.127:8766/api/xxxx/ 这个地址去拼接后面的地址去请求
还有nginx是从上到下来匹配的,精确匹配要写在模糊匹配之后,才不会出错
二、地址最后后面没有/,则不会被截取,直接在http://xx.x.xx.xx:8030'拼接,如果需要改地址,则在重写里面改
'/xxxx-xxx-xx/xx-xxxx': { target: 'http://xx.x.2x.8x:8xx0', changeOrigin: true, pathRewrite: { '^/jxxxx-cxxx-xx/px-bxxx': '/jxxx-cxxx-xx/px-bxxx' } },
三、先在浏览器上输入地址看能不能通,然后再在nginx代理,注意,这是顺序
#user root; worker_processes 9; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { client_max_body_size 10m; include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream api-gateway { #server 10.1.21.136:8766; #server 10.10.203.127:8765; server 10.10.203.127:8766; } upstream api-door { server 10.10.203.126:8765; } upstream api-dev{ server 10.101.90.121:8765; } upstream alarm-ws { server 10.10.203.127:8968; } server { listen 8089; # server_name t.jslife.net; server_name 10.10.203.127; #ssl on; # listen 443 ssl; #ssl_certificate cert.pem; #ssl_certificate_key cert.key; #ssl_session_cache shared:SSL:1m; #ssl_session_timeout 5m; #ssl_ciphers HIGH:!aNULL:!MD5; #ssl_prefer_server_ciphers on; #charset koi8-r; #access_log logs/host.access.log main; #jpark-center-mgr location ~ ^/(xjxx-mxxx-xxx)/.*\.(html|js|map|css|gif|jpg|png|woff|woff2|ttf|eot|svg|json)$ { add_header Content-Security-Policy 'frame-ancestors self http://t.jslife.net'; root html; } location ~ ^/(xjxx-xc-mxx)/.*\.(html|js|map|css|gif|jpg|png|woff|woff2|ttf|eot|svg|json)$ { root html; } location ~ ^/(dxx-cxxx)/.*\.(html|js|map|css|gif|jpg|png|woff|woff2|ttf|eot|svg|json)$ { root html; } # location ~ ^/(xxxx-cxxx-mxx)/.*\.(html|js|map|css|gif|jpg|png|woff|woff2|ttf|eot|svg|json)$ { # root html; # } #/api/jsis #/api/admin #/api/tools #/api/auth #/api/jsrmbiz # location /xxxx-cxx-mgr/api { proxy_pass http://api-gateway/api; proxy_connect_timeout 18000; proxy_send_timeout 18000; proxy_read_timeout 18000; } location test/xxxx-cxx-mgr/api { proxy_pass http://10.10.206.81:8765/api; proxy_connect_timeout 18000; proxy_send_timeout 18000; proxy_read_timeout 18000; } location /vx.x { proxy_pass http://api-gateway; proxy_connect_timeout 18000; proxy_send_timeout 18000; proxy_read_timeout 18000; } location /jxxxx-dxxr{ proxy_pass http://api-dxxx/axx; proxy_connect_timeout 18000; proxy_send_timeout 18000; proxy_read_timeout 18000; } location /xxxx-cxxx-mgr/dev/api{ proxy_pass http://api-dev/api; proxy_connect_timeout 18000; proxy_send_timeout 18000; proxy_read_timeout 18000; } location / { add_header Cache_Control "no-cache, no store"; root html; index index.html index.htm; try_files $uri $uri/ /index.html; } location /xspo-xc-xgr/base { proxy_pass http://1x.1x.2xx.127:8730/base; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } location /xxpo-xc-xgr/data { proxy_pass http://1x.1x.2xx.127:8730/data; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } location /xxpm-center-mgr/api/jsis/toxx-xxxService/ { proxy_pass http://1x.1x.2xx.1xx:8766/api/jsis/; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } # location /jspm-center-mgr/api/jsis/tojscp-parkService/ { # proxy_pass http://10.10.203.127:8767/; # } # 车xx1.2新增 location /xxxx-xxxx-mgr/api/jsis/toxxxx/ { proxy_pass http://1x.1x.2x.xxx:8766/api/jsis/; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } #车xxx location /xxxxx-center-mgr/pm-base { proxy_pass http://1x.1x.2xx.14x:8765/pm-base; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } #车xxxx location /xxxx-center-mgr/pm-base { proxy_pass http://1x.1x.2xx.1x8:8765/pm-base; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } #车xxxx location /wx { proxy_pass http://wx.indoorun.com; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } location /xxxx-center-mgr/ws { proxy_pass http://alarm-ws/jsiscp-warnservice; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } #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; } location /pic { root /home/jht/; autoindex on; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
location /jxx-cxxx-mgr/api/jxxx/txxx/ {
proxy_pass http://10.10.203.127:8766/api/jsis/;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!