您好,我正在尝试将我的产品组合部署到 Ubuntu Server 16.04,但我不断收到内部服务器错误。
为了完成我所做的事情,我创建了实例并将 HTTP 和 HTTPS 安全设置更改为任何地方。
之后我启动了实例然后运行这些命令
ubuntu@ip-172-31-41-27:~ sudo apt-get update
ubuntu@ip-172-31-41-27:~$ sudo apt-get install python-pip python-dev
nginx git
ubuntu@ip-172-31-41-27:~$ sudo apt-get update
ubuntu@ip-172-31-41-27:~$ sudo pip install virtualenv
ubuntu@ip-172-31-41-27:~/portfolio$ virtualenv venv --python=python3
ubuntu@ip-172-31-41-27:~/portfolio$ source venv/bin/activate
(venv)ubuntu@ip-172-31-41-27:~/portfolio$ pip install -r
requirements.txt
(venv) ubuntu@ip-172-31-41-27:~/portfolio$ pip install django bcrypt
django-extensions
(venv) ubuntu@ip-172-31-41-27:~/portfolio$ pip install gunicorn
我编辑了 settings.py
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['52.14.89.55']
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
然后运行,
(venv) ubuntu@ip-172-31-41-27:~/portfolio$ python manage.py
collectstatic
其次是,
ubuntu@ip-172-31-41-27:~/portfolio$ sudo vim
/etc/systemd/system/gunicorn.service
我在哪里添加
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/portfolio
ExecStart=/home/ubuntu/portfolio/venv/bin/gunicorn --workers 3 --bind
unix:/home/ubuntu/portfolio/portfolio.sock portfolio.wsgi:application
[Install]
WantedBy=multi-user.target
然后是 gunicorn 重启
ubuntu@ip-172-31-41-27:~/portfolio$ sudo systemctl daemon-reload
ubuntu@ip-172-31-41-27:~/portfolio$ sudo systemctl start gunicorn
ubuntu@ip-172-31-41-27:~/portfolio$ sudo systemctl enable gunicorn
最后,
ubuntu@54.162.31.253:~$ sudo vim /etc/nginx/sites-
available/portfolio
添加
server {
listen 80;
server_name 52.14.89.55;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/portfolio;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/portfolio/portfolio.sock;
}
}
创建链接
ubuntu@ip-172-31-41-27:/etc/nginx/sites-enabled$ sudo ln -s
/etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled
ubuntu@ip-172-31-41-27:/etc/nginx/sites-enabled$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
deleting the default
然后重新启动
ubuntu@ip-172-31-41-27:/etc/nginx/sites-enabled$ sudo service nginx
restart
编辑**
我更改了以下代码以完全匹配我所做的。