Nginx + uWSGI + Django 설정

yum install nginx.x86_64
django 프로젝트 디 렉 터 리 / mydj / logview
cp /etc/nginx/uwsgi_params /mydj/logview/
cd 부터 / my dj / 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 --ini uwsgi.ini
첫 페이지 테스트 열기 http://
정지
uwsgi --stop uwsgi.pid
문제 의 배열 이 틀리다.
로그 / mydj / logview / uwsgi. log
nginx 로그 / var / log / nginx / access. log & error. log

좋은 웹페이지 즐겨찾기