Django在centos上部署

william-xue發表於2018-04-15

uwsgi安裝 pip install uwsgi

測試uwsgi到python是否OK 在專案根目錄下建立test.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"]

使用的測試命令: uwsgi --http :8000 --wsgi-file test.py 在瀏覽器上訪問IP:8000

測試uwsgi到django是否ok 1.首先保證django是正常的 使用的測試命令:uwsgi -http :8000 --module mysite.wsgi #專案的wsgi 瀏覽器輸入 IP:8000 進行測試

2.在專案根目錄建立 uwsgi.ini [uwsgi] socket = 伺服器IP:8000 chdir = /home/foobar/myproject/ wsgi-file = myproject/wsgi.py processes = 4 threads = 2 stats = 伺服器IP:9191

安裝nginx yum install nginx 在 /etc/nginx/conf.d/下建立 blog.conf upstream django { server 192.168.100.12:8000; #對應uwsgi.ini中socket }

configuration of the server

server { listen 80; #對應瀏覽器 server_name 192.168.100.12; charset utf-8;

access_log  /var/log/nginx/blog_access.log;

client_max_body_size 8M;   # adjust to taste

location /media  {
    alias /usr/local/site/demo/project-blog/media;
}

location /static {
    alias /usr/local/site/demo/project-blog/static;
}

location / {
    uwsgi_pass  django;
    include     /etc/nginx/uwsgi_params;
}
複製程式碼

}

相關文章