欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程

 更新時間:2014年11月18日 09:00:42   投稿:hebedich  
django+uwsgi的部署實(shí)在是太蛋疼了.網(wǎng)上已有的教程似乎有新版本的兼容問題。最后跑到uwsgi官網(wǎng)上找的教程終于跑通了.. 不過官網(wǎng)的教程似乎有引導(dǎo)教學(xué)性質(zhì),部署的時候就顯得很繞彎路,在這里記錄下來精簡內(nèi)容

具體環(huán)境:
Ubuntu 14.04 Python 2.7.6 Django 1.7.1 Virtualenv name:test Nginx uwsgi

假設(shè) 項(xiàng)目文件夾位于 /data/www/ts 設(shè)置保存在 ./conf

復(fù)制代碼 代碼如下:

virtualenv name = test
domain name = example.com

django+uwsgi的部署實(shí)在是太蛋疼了..網(wǎng)上已有的教程似乎有新版本的兼容問題。最后跑到uwsgi官網(wǎng)上找的教程終于跑通了..
不過官網(wǎng)的教程似乎有引導(dǎo)教學(xué)性質(zhì),部署的時候就顯得很繞彎路,在這里記錄下來精簡內(nèi)容

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

首先,需要一個uwsgi_params文件,放在項(xiàng)目的conf文件夾里面。之后需要指向它。文件內(nèi)容如下:

復(fù)制代碼 代碼如下:

uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;

創(chuàng)建一個叫做ts_nginx.conf 的文件,內(nèi)容如下

復(fù)制代碼 代碼如下:

# ts_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8001; # 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 .example.com; # 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 /data/www/ts/media; # your Django project's media files - amend as required
    }

    location /static {
        alias /data/www/ts/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 /data/www/ts/conf/uwsgi_params; # the uwsgi_params file you installed
    }
}

把這個conf文件連接到nginx的搜索目錄里面。

復(fù)制代碼 代碼如下:

sudo ln -s /data/www/ts/conf/ts_nginx.conf /etc/nginx/sites-enabled/

先決條件:這里要設(shè)置好django項(xiàng)目的settings里面static files

復(fù)制代碼 代碼如下:

STATIC_ROOT = os.path.join(BASE_DIR, "static/")
and then run

python manage.py collectstatic

之后:

復(fù)制代碼 代碼如下:

service nginx restart

應(yīng)該就可以看到
http://example.cn:8000/media/1.gif
了(事先放進(jìn)去一個靜態(tài)文件)

之后的blabla步驟都是廢話,跳到這里:

復(fù)制代碼 代碼如下:

Configuring uWSGI to run with a .ini file

ts_uwsgi.ini 在項(xiàng)目根目錄

復(fù)制代碼 代碼如下:

[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /data/www/ts
# Django's wsgi file
module = ts.wsgi
# the virtualenv (full path)
home = /root/.envs/test
# 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:8001
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
# set an environment variable
env = DJANGO_SETTINGS_MODULE=conf.settings
uwsgi --ini mysite_uwsgi.ini # the --ini option is used to specify a file

這里環(huán)境變量設(shè)置env需要conf文件夾有init.py,否則conf不會被認(rèn)為是module

(目前除了80端口,其他端口都可以通過地址:端口訪問。已經(jīng)測試8000,81.80測試不知道為什么不成。明天待續(xù))

相關(guān)文章

  • python解析模塊(ConfigParser)使用方法

    python解析模塊(ConfigParser)使用方法

    很多軟件都有配置文件,今天介紹一下python ConfigParser模塊解析配置文件的使用方法
    2013-12-12
  • Python3爬蟲mitmproxy的安裝步驟

    Python3爬蟲mitmproxy的安裝步驟

    在本篇文章里小編給大家整理的是關(guān)于Python3爬蟲mitmproxy的安裝步驟,需要的朋友們可以學(xué)習(xí)下。
    2020-07-07
  • python字符串編碼識別模塊chardet簡單應(yīng)用

    python字符串編碼識別模塊chardet簡單應(yīng)用

    有時候需要先檢測一個文件的編碼,然后將其轉(zhuǎn)化為另一種編碼。這時候就會用到chardet(chardet是python的一個第三方庫,是非常優(yōu)秀的編碼識別模塊)
    2015-06-06
  • 解決yum對python依賴版本問題

    解決yum對python依賴版本問題

    這篇文章主要介紹了解決yum對python依賴版本問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • Python用matplotlib庫畫圖中文和負(fù)號顯示為方框的問題解決

    Python用matplotlib庫畫圖中文和負(fù)號顯示為方框的問題解決

    matplotlib中畫圖的時候會遇到負(fù)號顯示為方框的問題,下面這篇文章主要給大家介紹了關(guān)于Python用matplotlib庫畫圖中文和負(fù)號顯示為方框的問題解決,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • python使用三角迭代計算圓周率PI的方法

    python使用三角迭代計算圓周率PI的方法

    這篇文章主要介紹了python使用三角迭代計算圓周率PI的方法,實(shí)例分析了Python迭代算法的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • python用socket傳輸圖片的項(xiàng)目實(shí)踐

    python用socket傳輸圖片的項(xiàng)目實(shí)踐

    使用python在網(wǎng)絡(luò)上傳送圖片數(shù)據(jù),需要以byte格式讀取圖片,這樣才可以通過socket傳輸,本文就來介紹了python用socket傳輸圖片的項(xiàng)目實(shí)踐,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • pygame仿office的頁面切換功能(完整代碼)

    pygame仿office的頁面切換功能(完整代碼)

    本文通過兩個版本給大家介紹pygame實(shí)現(xiàn)類似office的頁面切換功能,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-05-05
  • python 內(nèi)置函數(shù)filter

    python 內(nèi)置函數(shù)filter

    這篇文章主要介紹了python 內(nèi)置函數(shù)filter的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • 使用Python FastAPI構(gòu)建Web服務(wù)的實(shí)現(xiàn)

    使用Python FastAPI構(gòu)建Web服務(wù)的實(shí)現(xiàn)

    這篇文章主要介紹了使用Python FastAPI構(gòu)建Web服務(wù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06

最新評論