[英]Issues with nginx reverse proxy to an app server running nginx+django
I have an app running on Server A. I have a Server B that I want to use as a reverse proxy for accessing the app on Server A. Server A is running nginx 1.4.5 and Django (Python 2.7.6 with fastcgi), Server B is running nginx 1.4.5 as well. 我有一个在服务器A上运行的应用程序。我有一个服务器B,我想用作访问服务器A上应用程序的反向代理。服务器A运行Nginx 1.4.5和Django(带有fastcgi的Python 2.7.6),服务器B也正在运行nginx 1.4.5。 I also want to add on SSL that way.
我也想以这种方式添加SSL。
The proxy is kinda working. 代理有点工作。 The issue is that requests don't see to get passed along correctly.
问题是请求看不到正确传递。 When going to https://servera.org/ I only get a 404 error instead of the log-in page I'm expecting.
转到https://servera.org/时 ,只会收到404错误,而不是我期望的登录页面。
This is the error message I am seeing in the browser (it's an error message, so I know the request is reaching Server A): 这是我在浏览器中看到的错误消息(这是一条错误消息,因此我知道请求已到达服务器A):
Page not found (404)
Request Method: GET
Request URL: http://nova.iguw.tuwien.ac.at/index.html
Using the URLconf defined in TUBadges.urls, Django tried these URL patterns, in this order:
1. ^admin/doc/
2. ^admin/
3. ^$
4. ^badges/?$
5. ^badges/(?P<uid>\d+)/?$
6. ^presets/$
7. ^svg$
8. ^bgsvg$
9.
This is my config for the reverse proxy: 这是我的反向代理配置:
upstream server_a {
server servera.org:8080 fail_timeout=0;
}
server {
listen 443 ssl;
listen 80;
server_name subdomain1.serverb.org;
server_name subdomain2.serverb.org;
keepalive_timeout 70;
ssl_certificate /etc/certificates/server_b.pem;
ssl_certificate_key /etc/certificates/server_b.key;
error_log /var/log/nginx/aurora.ssl.error.log error;
access_log off;
client_max_body_size 50M;
location ~ ^/(.+)$ {
proxy_intercept_errors off;
proxy_buffering off;
proxy_connect_timeout 5;
proxy_send_timeout 5;
proxy_read_timeout 5;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-By $server_addr:$server_port;
proxy_set_header X-Forwarded-Fo $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
error_log /var/log/nginx/tubadges.error.log debug;
proxy_pass http://server_a;
proxy_redirect off;
}
}
And that is the config I'm using on Server A to run the app: 这就是我在服务器A上运行该应用程序所使用的配置:
server {
listen 8080; ## listen for ipv4
server_name localhost;
server_name servera.org;
client_max_body_size 5M;
error_log /var/log/nginx/app1.error.log;
access_log /var/log/nginx/app1.access.log;
location /static {
root /srv/django/projects/app1;
}
location /media {
root /srv/django/projects/app1;
}
location / {
# host and port to fastcgi server
fastcgi_pass unix:/srv/django/run/app1.socket;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
I'm assuming that it's got something to do with my Django App config or the config on Server A. 我假设这与我的Django App配置或服务器A上的配置有关。
Can you spot an error? 你能发现一个错误吗? Do you need more information?
你需要更多的信息?
Is there, maybe, an answer on here that I have just missed? 在这里,也许是我刚才错过的答案?
Thanks in advance! 提前致谢!
PS: This is my first time asking a question on StackOverflow, so if there's a way that I can improve my question to get better answers, and you see something that really bugs, please don't hesitate to point out to me how I can improve this question. PS:这是我第一次在StackOverflow上提问,所以如果有办法可以改善我的问题以获得更好的答案,并且您发现确实有问题,请不要犹豫地向我指出如何改善这个问题。 :)
:)
Actually, it looks like Nginx is correctly passing the request through - the error page comes from Django (so the request is being serviced by Apache) and it states that the url: 实际上,看起来Nginx正确地传递了请求-错误页面来自Django(因此请求由Apache提供服务),并指出了url:
http://nova.iguw.tuwien.ac.at/index.html http://nova.iguw.tuwien.ac.at/index.html
cannot be resolved to any of the urls defined in TUBadges.urls
无法解析为
TUBadges.urls
定义的任何URL
You need to hit a url such as http://nova.iguw.tuwien.ac.at/admin/login or something like that. 您需要点击一个网址,例如http://nova.iguw.tuwien.ac.at/admin/login或类似的网址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.