Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 16.04和记录

来源:互联网 发布:nginx 转发真实ip 编辑:程序博客网 时间:2024/06/01 11:41

How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04#create-a-gunicorn-systemd-service-file
—很好的文章,主要参考来自这里

按照这篇教程终于在python都没有写过的情况下将项目部署起来了。
期间遇到的问题:

2.关于数据库的,本身已经有了数据库db.sql文件,要做的就是将数据库导入进去。这里要注意的:

这里写图片描述
setting.py中的USER要和sql文件中的OWMER抑制,不然会有问题。。。(具体问题不记得了。。。。。)
这里写图片描述

2.关于GUNICORN的问题,关于配置gunicorn.service文件

这里写图片描述
文本如下:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn –access-logfile - –workers 3 –bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application

一开始一直不成功报如下错误
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2017-10-27 16:04:09 UTC; 13min ago
Main PID: 9039 (code=exited, status=203/EXEC)

Oct 27 16:04:09 polyphony systemd[1]: Started gunicorn daemon.
Oct 27 16:04:09 polyphony systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Oct 27 16:04:09 polyphony systemd[1]: gunicorn.service: Unit entered failed state.
Oct 27 16:04:09 polyphony systemd[1]: gunicorn.service: Failed with result ‘exit-code’.

一直纠结于User和Group的关系,各种更改项目的User和group试了sudo等都不成功,后来发现是WorkingDirectory路径配置的错误。
比如我的项目叫ciip在根目录下~/ciip,以root身份登入
那在这里的配置和home没有关系
User=root
Group=www-data
WorkingDirectory=/root/ciip(个人理解这里的root不是用户root而是路径~)
ExecStart=/root/ciip/ciipenv/bin/gunicorn –access-logfile - –workers 3 –bind unix:/root/ciipenv/ciip.sock ciip.wsgi:application

另外做一点小记录
1.下载PIL,pip install PIL已经不能运行了,说是使用pillow来代替,但是我要部署的项目版本问题,最终还是要使用PIL
sudo pip install http://effbot.org/media/downloads/Imaging-1.1.6.tar.gz
sudo pip install http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
这里写图片描述
截图来自https://stackoverflow.com/questions/8915296/python-image-library-fails-with-message-decoder-jpeg-not-available-pil
import PIL 语句也要改成from PIL import Image

2.export PATH=/usr/local/pgsql/bin:$PATH
这个可以解决很多路径不存在的问题,export一下就好了

3.用到的linux 命令
上传文件
scp questionnaire.html root@服务器地址: 服务器文件路径

下载文件
scp 用户名@服务器地址:文件路径 ~/Downloads(本地路径) 来实现下载

下载目录
scp -r 用户名@服务器地址:文件路径 ~/Downloads(本地路径) 来实现下载

ctrl+z项目后台运行

将/home/wwwroot/xahot/ 这个目录下所有文件和文件夹打包为当前目录下的xahot.zip
zip –q –r xahot.zip /home/wwwroot/xahot

将/home/wwwroot/xahot.zip解压到当前目录
unzip xahot.zip

很抱歉没有任何逻辑的文章,只是一个自己的记录方便以后遇到相同的问题可以找到答案

happy Halloween
这里写图片描述

阅读全文
0 0
原创粉丝点击