我的nginx无法在Ubuntu 16.04

时间:2018-04-15 09:20:58

标签: django nginx ubuntu-16.04 uwsgi

尝试运行django app" mysite"在Ubuntu 16.04上通过uwsgi与nginx,但是当我启动uwsgi并检查我的浏览器时,它只是挂起。

我将django上游套接字设置为端口8002和nginx设置为8003监听。在浏览器中,我在运行uwsgi之前访问192.168.0.17:8003并且它会抛出预期的502,所以我用

启动uwsgi

uwsgi --http :8002 --module mysite.wsgi --logto /tmp/uwsgi.log --master

当我在浏览器中重新加载时,

和8003现在挂起了。我浏览了/var/log/nginx/error.log,但它是空白的(access.log也是如此)。

这是nginx配置,符号链接到/etc/nginx/sites-enabled

sudo nano /etc/nginx/sites-available/mysite_nginx.conf

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8002; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8003;
    # the domain name it will serve for
    server_name 192.168.0.17; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/myusername/uwsgi-tutorial/mysite/media;  # your Django     project's media files - amend as required
    }

    location /static {
        alias /home/myusername/uwsgi-tutorial/mysite/static; # your Django     project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/myusername/uwsgi-tutorial/mysite/uwsgi_params; #     the uwsgi_params file you installed
    }
}

我知道Django正在运行,因为在我的应用程序中settings.py我有ALLOWED_HOSTS = ['192.168.0.17','localhost','127.0.0.1']当我在浏览器中访问端口8002时,我得到了django"祝贺!&# 34;页。当我从ALLOWED_HOSTS中删除192.168.0.17时,django仍然从localhost或127.0.0.1运行在该机器上,所以这似乎与ngnix和uwsgi如何相互通信有关。

任何想法??

1 个答案:

答案 0 :(得分:0)

事实证明,systemd不喜欢配置文件中的行太长。我在/etc/systemd/system/uwsgi.service删除了几条长评论,重新启动了uwgsi服务,一切都很顺利。

我通过运行sudo journalctl -u uwsgi找到了以下错误:

[/etc/systemd/system/uwsgi.service:5] Unbalanced quoting, ignoring: "/bin/bash -c 'mkdir -p /run/uwsgi; chown myusername:myusern

在研究不平衡报价时,发现this git issue有关最大文件行长度。

相关问题