简体   繁体   English

Nginx反向代理到运行Nginx + django的应用程序服务器的问题

[英]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.

相关问题 检查代理集标头是否被nginx反向代理(Django应用)所覆盖 - Checking proxy set header forwaded by nginx reverse proxy (Django app) 如何更改uwsgi(nginx + django)应用程序重新加载模式以减少首次请求的重新加载/等待延迟 - How to change uwsgi(nginx+django) app reload mode to decrease reload/wait latency for first request 无法使用 Nginx 反向代理连接到 Websocket 服务器 - Unable to connect to Websocket Server with Nginx reverse proxy Docker 与 NGINX 反向代理 Flask 应用程序 - Docker with NGINX Reverse Proxy for a Flask app 使用Postgres和Gunicorn + Nginx作为反向代理的Django应用程序中&#39;类型inet的输入语法无效&#39;db错误 - 'Invalid input syntax for type inet' db error in Django app with postgres and Gunicorn+Nginx as reverse proxy Nginx反向代理配置的问题,用于为多个Django应用程序Docker容器提供服务 - Troubles with nginx reverse proxy configuration for serving multiple Django app docker containers django SECURE_SSL_REDIRECT 与 nginx 反向代理 - django SECURE_SSL_REDIRECT with nginx reverse proxy Docker 和 Nginx 上的 uwsgi 作为反向代理 - uwsgi on Docker and Nginx as reverse proxy python simplehttpserver上的Nginx反向代理 - Nginx reverse proxy on python simplehttpserver 使用Nginx反向代理部署塔? - Deploying Pylons with Nginx reverse proxy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM