首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django-Gunicorn-Nginx部署没有通过Nginx

Django-Gunicorn-Nginx部署没有通过Nginx
EN

Stack Overflow用户
提问于 2017-08-19 12:47:15
回答 1查看 581关注 0票数 0

我试图在EC2实例上部署一个项目。

当我访问我的EC2实例URL时,我可以看到Nginx欢迎消息,但我似乎无法将它滚动到django中。

我有一个Gunicorn服务up和Nginx服务up,这些是他们的service status调用的输出:

古尼科恩:

gunicorn_mynew_website.service - Gunicorn守护进程用于我的新网站 加载:加载(/etc/systemd/system/gunicorn_mynew_website.service;已启用;供应商预置:已启用)活动:活动(运行)自Sat 2017-08-19 12:29:05世界协调时;主要PID: 1760任务:2内存:336m CPU: 368 2s :/ website .website/gunicorn_mynew_website.service├─1760 /opt/mynew/venv/bind venv/bin/python3.5/opt/mynew/venv/ website.wsgi:application -venv/bin/gunicorn website.wsgi:application-name网站-工人1-用户ubuntu -绑定=unix:/opt/mynew/run/gunicor└─1769 /└─/mynew/venv/└─-venv/bin/python3.5//mynew/venv/└─-名称网站1-用户ubuntu -绑定=unix:/opt/mynew/└─/└─ 8月19日12:29:05 ip-172-31-26-24 systemd1:为我的新网站启动Gunicorn守护进程。8月19日12:29:29:29 ip-172-31-26-24 gunicorn_start.sh1760:启动网站: ubuntu 19 12:29:05 ip-172-31-26-24 gunicorn_start.sh1760: 2017-08-19 12:29:05 +0000信息启动: gunicorn 19.7.1 8月19日12:29:05 ip-172-31-26-24 gunicorn_start.sh1760: 2017-08-19 12:29:05 +0000监听: unix:/opt/mynew/run/gunicorn.sock(1760) 8月19日12:29:05 ip-172-31-26-24 gunicorn_start.sh1760: 2017-08-19 12:29:05 +0000

Nginx

nginx.service -高性能web服务器和反向代理服务器加载: loaded (/lib/systemd/system/nginx.service;enabled;供应商预置: enabled) Active:自Sat 2017-08-19 11:34:14 UTC;56分钟前进程: 1151 ExecStart=/usr/sbin/nginx -g守护进程on;master_process on;(code=exited,status=0/SUCCESS)进程: 1090 ExecStartPre=/usr/sbin/nginx -t -q -g守护进程on;master_process on;(code=exited,status=0/SUCCESS)主要PID: 1165 (nginx)任务:2个内存:96m CPU: 24─:/systemd1.sbin/nginx.service├─1165 nginx:主进程/usr/sbin/nginx -g守护进程on;master_process on└─1166 nginx: worker process Aug 19 11:34:14 ip-172-31-26-24 systemd1:启动高性能web服务器和反向代理服务器.8月19日11:34:14 ip-172-31-26-24 systemd1:启动高性能web服务器和反向代理服务器。

我的`etc/nginx/nginx.conf (Http部分)是:

代码语言:javascript
复制
http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;



        upstream test_server {
          server unix:/opt/mynew/run/gunicorn.sock fail_timeout=10s;
        }

        server {
            listen   80;

            client_max_body_size 4G;

            access_log /opt/mynew/logs/nginx-access.log;
            error_log /opt/mynew/logs/nginx-error.log warn;

            location /static/ {
                autoindex on;
                alias   /opt/mynew/website/static/;
            }

            location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;

                if (!-f $request_filename) {
                    proxy_pass http://test_server;
                    break;
                }
            }

}

我的gunicorn_start.sh文件(服务):

代码语言:javascript
复制
#!/bin/bash

NAME="website"                              
DJANGODIR=/opt/mynew/website             
SOCKFILE=/opt/mynew/run/gunicorn.sock        
USER=ubuntu
GROUP=www-data
NUM_WORKERS=1
DJANGO_SETTINGS_MODULE=website.settings
DJANGO_WSGI_MODULE=website.wsgi
echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source /opt/mynew/venv/website-venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec /opt/mynew/venv/website-venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user $USER \
  --bind=unix:$SOCKFILE

我的django文件夹在/opt/mynew/website/

为了了解发生了什么,我故意在/website/website/settings.py中添加了一个异常,仅仅是为了查看gunicorn是否与它有关联,而当我启动gunicorn服务时,它确实失败了。

所以我猜是Nginx和火鸟之间的错..。

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-19 13:28:20

移除这2

代码语言:javascript
复制
include /etc/nginx/conf.d/*.conf; 
include /etc/nginx/sites-enabled/*; 

看看能不能用。默认情况下,nginx附带一个default.conf,它将侦听端口80,并使用静态nginx页面服务/var/www/html目录。所以要么知道你包含的每一个文件,要么不包括它们

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45771722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档