【问题标题】:Django deployment with nginx & gunicorn (godaddy domain/amazon ec2 instance)使用 nginx 和 gunicorn 部署 Django(godaddy 域/亚马逊 ec2 实例)
【发布时间】:2014-03-08 13:14:03
【问题描述】:

好的,所以我是一个刚刚完成 django 教程的网站新手,并决定尝试在网上发布我的投票应用程序。到目前为止,我有一个 Godaddy 域名,我试图将其指向我的亚马逊 EC2 实例的弹性 IP,该 IP 目前托管我的投票网站。

目前我设置的是:

Amazon 路由 53:指向 mydomain.com 的托管区域,记录集为:名称 mydomain.com & www.mydomain.com 和值 xx.xxx.xx.x

Godaddy:DNS 区域文件:A(主机)到我的亚马逊弹性 IP xx.xxx.xx.x,名称服务器到 4 亚马逊路由 53 个托管区域名称服务器。

EC2 实例:运行 nginx 和 gunicorn 来托管应用程序。

我的问题是我可以使用亚马逊的弹性 IP 访问该网站,但我无法使用域名访问它(我得到一个粗体的“欢迎使用 nginx!”页面无论我是否尝试访问主页或 /polls/1 页面。)

【问题讨论】:

    标签: django nginx amazon-ec2 dns


    【解决方案1】:

    看起来不错。您是否使用 nginx 遵循了标准 gunicorn 配置?

    http://docs.gunicorn.org/en/latest/deploy.html

    你可能想要在你的 nginx 配置上这样的东西:

    http {
        include mime.types;
        default_type application/octet-stream;
        access_log /tmp/nginx.access.log combined;
        sendfile on;
    
        upstream app_server {
            server unix:/tmp/gunicorn.sock fail_timeout=0;
            # For a TCP configuration:
            # server 192.168.0.7:8000 fail_timeout=0;
        }
    
        server {
            listen 443 default;
            client_max_body_size 4G;
            server_name _;
            ssl                  on;
            ssl_certificate      /usr/local/nginx/conf/cert.pem;
            ssl_certificate_key  /usr/local/nginx/conf/cert.key;
    
            keepalive_timeout 5;
    
            # path for static files
            root /path/to/app/current/public;
    
            location / {
                # checks for static file, if not found proxy to app
                try_files $uri @proxy_to_app;
            }
    
            location @proxy_to_app {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
    
                proxy_pass   http://app_server;
            }
    
            error_page 500 502 503 504 /500.html;
            location = /500.html {
                root /path/to/app/current/public;
            }
        }
    }
    

    您希望指向正确的 SSL 证书和密钥路径(而不是 /usr/local/nginx/conf/cert.pem;/usr/local/nginx/conf/cert.key;)。此外,您应该将 root 指向您的特定 Django 静态文件,而不是 /path/to/app/current/public

    【讨论】:

      【解决方案2】:

      好的,我想通了。

      Nginx 正在收听 127.0.0.1:8000,而 gunicorn 正在广播到 127.0.0.1:8001。 (502 错误)

      要修复 DNS 问题,我必须进入我的亚马逊 EC2 控制面板并打开端口 8000。

      【讨论】:

        猜你喜欢
        • 2013-11-07
        • 1970-01-01
        • 2010-12-28
        • 2014-10-08
        • 2014-03-30
        • 1970-01-01
        • 1970-01-01
        • 2020-05-12
        • 2014-08-09
        相关资源
        最近更新 更多