91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

nginx+uwsgi+django環境搭建的方法步驟

發布時間:2020-09-02 23:14:40 來源:腳本之家 閱讀:141 作者:陳某君 欄目:開發技術

環境搭建

1.安裝uwsgi、nginx和django

apt install nginx
pip install uwsgi
pip install django

2.測試uwsgi和nginx的連接

PS:下面的例子采用的是 unix socket 的鏈接發送

創文件foobar.py

def application(env, start_response):
  start_response('200 OK', [('Content-Type','text/html')])
  return [b"Hello World"] # python3
  #return ["Hello World"] # python2

創文件foobar_uwsgi.ini

[uwsgi]

# Django-related settings
# the base directory (full path)
chdir      = /home/dmd/project/ENV/mysite
# Django's wsgi file
module     = foobar

# process-related settings
# master
master     = true
# maximum number of worker processes
processes    = 10
# the socket (use the full path to be safe
socket     = /home/dmd/project/ENV/mysite/foobar.sock
# ... with appropriate permissions - may be needed
# chmod-socket  = 664
# clear environment on exit
# 這個配置本來是true,即退出就刪掉socket,但這會導致nginx的啟動失敗,所以改為false
vacuum     = false

創文件foobar_nginx.conf

server {
  listen     8099;
  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 unix:///home/dmd/project/ENV/mysite/foobar.sock; # 用unix socket
    # uwsgi_pass 127.0.0.1:8000 # 用TCP socket
    uwsgi_read_timeout 2;
  }
 }

將這個文件鏈接到/etc/nginx/sites-enabled,這樣nginx就可以看到它了

sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/

啟動nginx

sudo service nginx start

啟動uwsgi

uwsgi --ini foobar_uwsgi.ini

訪問127.0.0.1:8099,如果出現“Hello world”就說明下面連接棧是成功的。

the web client <-> the web server <-> the socket <-> uWSGI <-> Python

3.建立整個連接棧

the web client <-> the web server <-> the socket <-> uwsgi <-> Django

建立django項目

django-admin startproject mysite

在項目的根目錄建立mysite_uwsgi.ini

# myweb_uwsgi.ini file
[uwsgi]

# Django-related settings

socket = mysite.sock

# the base directory (full path)
chdir      = /home/dmd/project/ENV/mysite

# Django s wsgi file
module     = mysite.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     = false

在項目根目錄建立mysite_nginx.conf

server {
  listen     8099;
  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 unix:///home/dmd/project/ENV/mysite/mysite.sock; # 用unix socket
    # uwsgi_pass 127.0.0.1:8000 # 用TCP socket
    uwsgi_read_timeout 2;
  }
  location /static {
    expires 30d;
    autoindex on;
    add_header Cache-Control private;
    alias /home/dmd/project/ENV/mysite/static/;
   }
 }

鏈接sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/

運行

# 運行uwsgi
uwsgi --ini mysite_uwsgi.ini
# 開啟niginx
sudo service nginx start

測試。訪問 127.0.0.1:8099 ,如果看到django的頁面,說明成功。

完整的目錄樹

mysite/
├── db.sqlite3
├── manage.py
├── mysite
│  ├── __init__.py
│  ├── __pycache__
│  │  ├── __init__.cpython-36.pyc
│  │  ├── settings.cpython-36.pyc
│  │  ├── urls.cpython-36.pyc
│  │  └── wsgi.cpython-36.pyc
│  ├── settings.py
│  ├── urls.py
│  └── wsgi.py
├── mysite.sock
├── mysite_nginx.conf
├── mysite_uwsgi.ini
└── uwsgi_params

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

湾仔区| 邵东县| 谢通门县| 关岭| 广灵县| 霞浦县| 尚志市| 苍山县| 长汀县| 孙吴县| 临夏县| 阳新县| 广西| 项城市| 阳谷县| 武威市| 合江县| 馆陶县| 阳山县| 文安县| 宁国市| 望城县| 聂拉木县| 连云港市| 平江县| 安多县| 水城县| 靖州| 水富县| 延安市| 桂东县| 获嘉县| 理塘县| 长宁县| 嘉善县| 平谷区| 博乐市| 伊川县| 绥中县| 保山市| 阿荣旗|