Cpp*_*ner 2 nginx reverse-proxy ssh-tunnel django
我的问题与此非常相似:nginx proxy pass redirects ignore port
我正在使用 nginx 1.0.14。
我希望能够通过 ssh 隧道进入我的 Django 网站,以便我可以远程工作。我在我的个人电脑上测试了一个简单的 Django 项目,使用非常简单的 nginx 配置(启动器,默认)。我隧道和重定向返回端口号作为 url 的一部分。所以我确定这不是 Django 问题。主要是我的nginx配置。
这是相关的部分。
server {
listen 80;
server_name localhost 127.0.0.1;
server_name_in_redirect off;
# location other services go here
location ~ /forum/(.*)$ {
#rewrite ^(.*):(.*)/forum(.*)$ /$2 last;
#rewrite ^(.*)$ http://localhost:8000/$1;
#rewrite ^/forum(.*)$ $1 break;
# the forum service runs as local, listens to 8000 port...
proxy_pass http://localhost:8000;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Run Code Online (Sandbox Code Playgroud)
那么如果我 ssh-tunnel 会发生什么?
ssh -L 1111:192.168.1.165:80 username@server-address -N
Run Code Online (Sandbox Code Playgroud)
然后打开浏览器,http://localhost:1111当我登录或做任何需要重定向的事情时,我得到http://localhost/forum/front-page而不是 http://localhost:1111/froum/front-page
这些链接是错误的,nginx 会(从服务器端)抱怨它们不存在。
在内部,服务论坛运行于 http://localhost:8000
我试过类似的东西
proxy_set_header $host:$server_port; # or
proxy_set_header $proxy_host:$proxy_port; # or
proxy_set_header $host:$proxy_port; # or
rewrite ^(.*):(.*)/forum(.*)$ /$2 last;
#rewrite ^/forum(.*)$ $1 break;
proxy_redirect http://localhost/ http://$host:$proxy_port;
Run Code Online (Sandbox Code Playgroud)
第二个 proxy_set_header 显示了一点进展。按 后submit,我得到一个空白页面,其中包含原始 url(http://localhost:1111/post,然后我再次看到相同的 url)。
知道如何解决我的问题吗?谢谢。
所以我想出了一个简单的解决方案......作为我自己的答案......
proxy_set_header Host $host;
Run Code Online (Sandbox Code Playgroud)
$host应该替换为$http_host,虽然我不太确定两者的含义。
| 归档时间: |
|
| 查看次数: |
12384 次 |
| 最近记录: |