yum install nginx.x86_64
django 项目目录/mydj/logview
cp /etc/nginx/uwsgi_params /mydj/logview/
cd 到/mydj/logview, 创建文件 logview_nginx.conf
# logview_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///mydj/logview/mysite.sock; # for a file socket
#server 127.0.0.1:9000; # for a web port socket (we'll use this first)}
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 10.199.196.106; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /mydj/logview/media; # your Django project's media files - amend as required
}
location /static {
alias /mydj/logview/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /mydj/logview/uwsgi_params; # the uwsgi_params file you installed
}
}
cd /etc/nginx
mkdir sites-enabled
ln -s /mydj/logview/logview_nginx.conf /etc/nginx/sites-enabled/
修改/etc/nginx/nginx.conf 增加一条include 语句 “ include /etc/nginx/sites-enabled/*.conf;” 将原来的default.conf 从包含列表里移除(cd /etc/nginx/conf.d mv default.conf ..)
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}
部署静态文件
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
python manage.py collectstatic
Django目录下创建文件 uwsgi.ini
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /mydj/logview
# Django's wsgi file
module = logview.wsgi
# the virtualenv (full path)
#home = /path/to/virtualenv
# process-related settings# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
#socket = 127.0.0.1:9000
socket = /mydj/logview/mysite.sock
# ... with appropriate permissions - may be needed#
chmod-socket = 666
# clear environment on exit
vacuum = true
daemonize = /mydj/logview/uwsgi.log
修改 settings.py, 设置 ALLOWED_HOSTS = '*'
启动nginx
service nginx start
启动uwsgi
uwsgi --ini uwsgi.ini
打开首页测试 http://<ip>
停止uwsgi
uwsgi --stop uwsgi.pid
问题排错
wsgi 日志 /mydj/logview/uwsgi.log
nginx日志 /var/log/nginx/access.log & error.log