1. 程式人生 > >Nginx + uWSGI + Django 配置

Nginx + uWSGI + Django 配置

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



相關推薦

virtualenv+nginx+uwsgi+django配置

現有django app “mysite”,需要用nginx和uwsgi。 下圖是在virtualenv建立的虛擬環境下: A。單應用 1.安裝nginx,版本是1.13.4: 安裝gcc g++的依賴庫 #apt-get install build-ess

Nginx + uWSGI + Django 配置

yum install nginx.x86_64 django 專案目錄/mydj/logview cp /etc/nginx/uwsgi_params /mydj/logview/ cd 到/mydj/logview, 建立檔案 logview_nginx.conf #

nginx+uwsgi+Django配置

1、nginx 配置簡單配置# nginx 代理到 uwsgi server { listen 8080; server_name localhost; location / { include uwsgi_param

Django Nginx+uwsgi 安裝配置

在前面的章節中我們使用 python manage.py runserver 來執行伺服器。這隻適用測試環境中使用。 正式釋出的服務,我們需要一個可以穩定而持續的伺服器,比如apache, Nginx, lighttpd等,本文將以 Nginx 為例。 安裝基礎開發包

centos6.9 執行nginx+uWSGI+django+mysql伺服器一整套配置

(搬瓦工伺服器實測(全程為root使用者))python3安裝:編譯器安裝:yum -y install gcc依賴包安裝:yum -y install bzip2-devel sqlite-devel openssl-devel readline-devel xz-deve

Django+Nginx+uwsgi 安裝配置

python manage.py runserver 來執行伺服器,但這隻適用測試環境中使用。 正式釋出的服務,我們需要一個可以穩定而持續的伺服器,比如apache, Nginx, lighttpd等,本文將以 Nginx 為例。 安裝基礎開發包 Centos 下安裝步

Nginx+uWSGI+Django原理(轉發)

.html web服務器 開始 git 性能 ast host common protocol Python的Web開發中,如果使用Django框架,那麽較為成熟穩定的服務器架構一般是Nginx+uWSGI+Django。而為什麽一定要三個結合在一起呢?直接使用Django

五步教你實現使用Nginx+uWSGI+Django方法部署Django程序

設置 wsgi alias admin 生效 server static 出現 mar 新建一個XML文件: djangochina_socket.xml,將它放在/data/www/org_management目錄下: Nginx采用8077端口與uWSGI通訊,請確保此

ubuntu 16.04部署python項目(Nginx+uwsgi+django

也有 src cnblogs 就是 主機 serve .cn ket essential 嘗試在linux上部署項目,先從最熟悉的python項目開始吧。 1、安裝Nginx 命令:sudo apt-get install nginx 2、安裝uwsgi,從pip倉庫安裝

nginx+uWSGI+django

Go 響應 信息 而是 支持php php 框架 soft 交互 要求: 構建nginx+uWSGI+python的web-service服務 nginx:常用高性能代理服務器; uWSGI:一個基於自有的uwsgi協議、wsgi協議和http服務協議的web網關; Dja

Nginx+uWSGI+Django部署web服務器

使用配置 -- tin 排除 允許 發布 enable ble chdir 目錄 Nginx+uWSGI+Django部署web服務器 環境說明 前言 搭建項目 Django部署 編輯luffy/luffy/settings.py 編輯luffy/app01/views.

centos7下部署Djangonginx+uwsgi+django+python3)

參考文獻: https://blog.csdn.net/anifans9350/article/details/80145535 https://www.cnblogs.com/dalanjing/p/8636338.html   0.安裝步驟預覽(1)系統預設自帶python2.x,所以需

nginx+uWSGI+django+virtualenv+supervisor部署發布web項目

content its object src Pythonweb system perm 會有 targe Nginx (engine x) 是一個高性能的HTTP和反向代理服務,也是一個IMAP/POP3/SMTP服務。 wsgi是PythonWeb服務器網關接口(We

nginx+uWSGI+django+virtualenv+supervisor釋出web伺服器 nginx+uWSGI+django+virtualenv+supervisor釋出web伺服器

1.單機啟動django專案,效能低,預設使用wsgiref模組,效能低的wsgi協議 python3 manager.py runserver 0.0.0.0:8000 > wsgiref模組中 2.高併發啟動django,django是沒有這個功能的,而uWSGI模組,遵循uwsgi協

nginx+uwsgi+django開發環境搭建

Nginx+uWSGI+Djangoi開發環境搭建 Django簡介,環境搭建 uWSGI簡介,安裝與配置 Nginx安裝與配置 Nginx+uWSGI+Django原理解析   1、django簡介,環境搭建 django簡介 Django 是用Python開發的一個免費開源的We

專案部署nginx+uwsgi+django

1.概念 Django專案(web應用) web服務 nginx:高併發處理的好 Apache:穩定 LAMP:Linux Apache MySQL Python/Php/Per1 LNMP:Linux Nginx    My

Nginx+uWSGI+Django部署web伺服器

一.搭建專案     1.建立一個虛擬環境         建議個人學習和測試的話,直接建在 /home/ubuntu/使用者/ 目錄下, virtualenv -p python3 py

Nginx+Uwsgi+Django+Python伺服器部署及除錯(更新0.1)

Nginx+Uwsgi+Django+Python伺服器部署 環境:Ubuntu16.04 1.python開發環境 安裝pyenv,python,virtualenv,需要使用python虛擬環境env 2.安裝配置nginx 安裝 sudo apt-get ins

ubuntu16.04下nginx+uwsgi+django伺服器部署

1.python開發環境 安裝pyenv,python,virtualenv,需要使用python虛擬環境env365 2.安裝配置nginx 安裝 sudo apt-get install nginx 配置 cd /etc/nginx/sites-available cp

linux環境,從零開始搭建nginx+uwsgi+django環境(二)

第四步 安裝nginx及mariadb        4.1、安裝nginx                yum install nginx               或從原始碼安裝:                     執行下面的指令: