我使用 Nginx 作为反向代理。我假设我有一个像 test.com 这样的域和一个像 /test 这样的路径的位置块。该位置将 proxy_pass 到另一个网站,例如http://test2.com。当我在浏览器上键入 URL 时,它会将第一个请求重定向到应用程序(http://test.com/test/ --> http://test2.com/)。但是,所有传入的请求都将在没有我在 Nginx 上定义的位置的情况下发送。如何使所有传入请求都遵循该路径?我想要这样的东西:
第一个请求:http ://test.com/test/ --> http://test.com
http://test.com/test/api/something等等...
server { listen 80; charset utf-8; server_name test.com; location = /auth/test{ internal; proxy_pass http://test.com/test/decisions/; proxy_pass_request_body off; proxy_set_header Content-Length ''; proxy_set_header X-Original-URI $request_uri; } location = /test/decisions/ { 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_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Authorization $http_authorization; proxy_pass http://valid.domain/test/api/authorization; } location /test/ { auth_request /auth/test; auth_request_set $auth_status $upstream_status; 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_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Authorization $http_authorization; proxy_pass https://test2.com/; proxy_pass_header Server; proxy_http_version 1.1; proxy_redirect default; access_log /var/log/nginx/access.log; client_max_body_size 10240M; } }