系統環境: CentOS6.4 x64
nginx+php配置
1.安裝php-fpm
yum install php-fpm -y
service php-fpm start
chkconfig php-fpm on
2.編輯 /etc/nginx/nginx.conf文件
1 user nginx; 2 worker_processes 1; 3 4 error_log /var/log/nginx/error.log warn; 5 pid /var/run/nginx.pid; 6 7 8 events { 9 worker_connections 1024; 10 } 11 12 13 http { 14 include /etc/nginx/mime.types; 15 default_type application/octet-stream; 16 17 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 18 '$status $body_bytes_sent "$http_referer" ' 19 '"$http_user_agent" "$http_x_forwarded_for"'; 20 21 access_log /var/log/nginx/access.log main; 22 23 sendfile on; 24 #tcp_nopush on; 25 26 keepalive_timeout 65; 27 28 #gzip on; 29 30 include /etc/nginx/conf.d/*.conf; 31 server 32 { 33 listen 8080; 34 server_name localhost; 35 root /var/www/html; 36 index index.html index.php; 37 location ~* \.php$ { 38 fastcgi_pass 127.0.0.1:9000; 39 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 40 fastcgi_param PATH_INFO $fastcgi_script_name; 41 include fastcgi_params; 42 } 43 } 44 }
nginx + django + uwsgiphp
1.安裝uWSGI
安裝依賴包
yum install python python-devel libxml2 libxml2-devel python-setuptools zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake python-piphtml
經過pip安裝
pip install uWSGIpython
2. nginx配置文件修改.
/etc/nginx/nginx.confnginx
server { listen 80; server_name 172.16.253.160; location / { root /var/www/html/PillarsCGSystem; uwsgi_pass 127.0.0.1:8630; include uwsgi_params; access_log off; } location /static { alias /var/www/html/PillarsCGSystem/static; } location /media { alias /var/www/html/PillarsCGSystem/media; } }
root: django: app目錄
uwsgi_pass: uwsgi服務器的地址與端口號,與uwsgi配置文件中的必須相同.
設定static和media目錄的位置.django
3.在django項目根目錄下建立wsgi.py文件,內容以下服務器
import os,sys if not os.path.dirname(__file__) in sys.path[:1]: sys.path.insert(0, os.path.dirname(__file__)) os.environ['DJANGO_SETTINGS_MODULE'] = '項目名稱.settings' from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()
4.django項目根目錄下建立django.xml文件,內容以下.app
<uwsgi> <socket>127.0.0.1:8630</socket> <chdir>/var/www/html/PillarsCGSystem</chdir> <pythonpath>..</pythonpath> <module>wsgi</module> </uwsgi>
5.啓動uwsgi服務器.socket
uwsgi -x django.xmltcp