【问题标题】:server name doesn't work (django + nginx + gunicorn)服务器名称不起作用(django + nginx + gunicorn)
【发布时间】:2012-10-15 12:18:19
【问题描述】:

这是我第一次使用 django + nginx + gunicorn。我无法使 server_name 工作。通过以下配置,我可以在 localhost/admin 上看到 django 管理面板。但是当我访问 local-example/admin 时,我也应该能够看到管理面板吗?

启动我的独角兽

gunicorn web_wsgi_local:application
2012-10-14 19:45:50 [16532] [INFO] Starting gunicorn 0.14.6
2012-10-14 19:45:50 [16532] [INFO] Listening at: http://127.0.0.1:8000 (16532)
2012-10-14 19:45:50 [16532] [INFO] Using worker: sync
2012-10-14 19:45:50 [16533] [INFO] Booting worker with pid: 16533

nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /Users/ruixia/www/x/project/logs/nginx_access.log  main;
    error_log /Users/ruixia/www/x/project/logs/nginx_error.log debug;

    autoindex on;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    off;

    gzip  on;

    include /usr/local/etc/nginx/sites-enabled/*;
}

启用站点/x 配置

server {
    listen 80;
    server_name local-example;
    root /Users/ruixia/www/x/project;

    location /static/ {
        alias /Users/ruixia/www/x/project/static/;
        expires 30d;
    }

    location /media/ {
        alias /Users/ruixia/www/x/project/media/;
    }

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://localhost:8000/;
    }
}

【问题讨论】:

    标签: django nginx gunicorn


    【解决方案1】:

    嗯...我通过将 local-example 添加到 /etc/hosts 解决了这个问题

    【讨论】:

    • 我正在寻找与上述类似问题的解决方案。我无法使用网络服务器的 IP 地址或主机名在网络内远程访问我的 django。我已经在 /etc/hosts 中添加了网络服务器名称。我在防火墙中添加了要打开的端口。任何指针都非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 2015-03-30
    • 2012-05-29
    • 2014-04-03
    • 2012-05-27
    • 1970-01-01
    • 2018-01-17
    相关资源
    最近更新 更多