DEBUG = False ALLOWED_HOSTS = ['*']
sudo apt-get install build-essential sudo apt-get install libtool
安裝 pcre依賴庫
html
sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev
python安裝 zlib依賴庫(若是報錯,需再安裝ruby):
$sudo apt-get install rub sudo apt-get install zlib1g-dev
在nginx官網下載nginx1.8.1而後解壓
./configure --prefix=/usr/local/nginx
#編輯nginx:
make
#安裝nginx:
sudo make install
#啓動nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路徑,不加的話,nginx會自動加載默認路徑的配置文件,能夠經過 -h查看幫助命令。
#查看nginx進程:
ps -ef|grep nginx
中止 Nginx服務器(
/usr/local/nginx/sbin/nginx -s stop /usr/local/nginx/sbin/nginx -s quit
能夠將nginx路徑加入系統的環境變量中,就無需寫路徑了:nginx -s stop
3.安裝uwsgi:
python3 -m pip install uwsgi
nginx
4.django+nginx+uwsgi
在項目目錄下建立myweb_uwsgi.ini配置文件(就是和manag.py同級)
# myweb_uwsgi.ini file[uwsgi] # Django-related settings socket = :8000(django項目啓動的端口) # the base directory (full path) chdir = /home/fnngj/pydj/myweb(項目路徑) # Django s wsgi file module = myweb.wsgi(注意) # process-related settings # master master = true # maximum number of worker processes processes = 4 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true
uwsgi --ini django_hotel_uwsgi.ini
/usr/local/nginx/conf/nginx.conf
文件,添加以下內容server { listen 10000; (外網訪問端口設置;要防火牆打開了這個端口,否則外網沒法訪問) server_name 127.0.0.1 charset UTF-8; access_log /var/log/nginx/myweb_access.log; error_log /var/log/nginx/myweb_error.log; client_max_body_size 75M; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8000; uwsgi_read_timeout 2; } location /static { expires 30d; autoindex on; add_header Cache-Control private; alias /home/fnngj/pydj/myweb/static/;(靜態文件地址) } }
啓動nginx而後,訪問:http://127.0.0.1:10000