updated at 2018-04-02
参照:www.digitalocean.com/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-centos-7
sudo vim /etc/systemd/system/gunicorn.service[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ouyi
Group=ouyi
WorkingDirectory=/home/ouyi/creditmg
EnvironmentFile=/home/ouyi/creditmg/.env
ExecStart=/home/ouyi/.local/share/virtualenvs/creditmg-F6Yq17ql/bin/gunicorn \
--worker-class=gevent --workers 3 \
--bind unix:/home/ouyi/creditmg/gunicorn.sock creditmg.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
sudo vim /etc/nginx/nginx.conf
server {
charset utf-8;
listen 80;
listen [::]:80;
server_name gullwing.cn 120.78.198.93;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
alias /home/ouyi/creditmg/collectstatic;
}
location /media {
alias /home/ouyi/creditmg/media;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/ouyi/creditmg/gunicorn.sock;
# proxy_read_timeout 300;
}
}
sudo usermod -a -G `whoami` nginx
chmod 710 /home/`whoami`
sudo nginx -t
sudo systemctl start nginx
sudo systemctl enable nginx
PS: 查看与用户同名的组有哪些成员:
cat /etc/group|grep `whoami`
adm:x:4:syslog,ubuntu
dialout:x:20:ubuntu
cdrom:x:24:ubuntu
floppy:x:25:ubuntu
sudo:x:27:ubuntu
audio:x:29:ubuntu
dip:x:30:ubuntu
video:x:44:ubuntu
plugdev:x:46:ubuntu
netdev:x:109:ubuntu
lxd:x:110:ubuntu
ubuntu:x:1000:
#组名称 组密码 组ID(GID) 组成员
新建与用户同名的组:
groupadd `whoami`
------------------------------------------
2017-10-31
关键步骤:
nginx.conf中设置
proxy_pass http://172.18.204.154:9000; # 172.18.204.154为阿里云私网IP
终端启动
nohup gunicorn --worker-class=gevent romanloaddotcom.wsgi:application -b 172.18.204.154:9000&
其它基本参照:http://www.isaced.com/post-248.html