【发布时间】:2020-09-23 20:05:18
【问题描述】:
我将尝试在我的服务器 URL 的 nginx 中处理对我服务器上另一个服务的所有请求。该服务不应该从外部可见,因此我将使用 nginx 的反向代理功能。 所以对nginx的请求应该是例如:
- https://foo.url => http://localhost:2424
- https://foo.url/page1 => http://localhost:2424?_=/page1
- https://foo.url/sub1/page2 => http://localhost:2424?_=/sub1/page2
目前我不需要获取参数,但如果它们也能工作当然会很好,即:
- https://foo.url/page1?xxx=abc => http://localhost:2424?_=/page1&xxx=abc
目前我的配置是这样的:
...
location / {
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://localhost:1234/;
proxy_set_header Proxy "";
...
当然不会重定向子页面。但以下也不起作用:
...
location /(.*) {
# location ~ /(.*) { # I tried this too
...
proxy_pass http://localhost:1234/?_=$1;
...
谁能帮帮我?
【问题讨论】:
标签: nginx reverse-proxy