樹莓派中nginx+uwsgi+flask局域網服務器配置

flask項目本地調試不需要另外裝服務器,本身自帶。但要部署到生產環境需要依賴更強大穩定的服務器,這裏使用nginx+uwsig,這兩個都需要另外安裝。

uwsgi配置:

項目文件夾下的uwsgi.ini配置文件:

[uwsgi]
socket = 192.168.1.11:8000
chdir = /home/pi/Project/MonitorServer#項目目錄
wsgi-file = index.py#項目文件
callable = app#flask變量名,即index.py中app = Flask(__name__)
processes = 4

nginx配置:

/etc/nginx/sites-available/default配置文件:

server {
    listen 8888 default_server;#修改成8888
    listen [::]:8888 default_server;#修改成8888
    #root /var/www/html;#註釋掉
    # Add index.php to the list if you are using PHP
    #index index.html index.htm index.nginx-debian.html;#註釋掉
    server_name _;
    location / {
	    include uwsgi_params;#添加
        uwsgi_pass 192.168.1.11:8000;#添加
	    # First attempt to serve request as file, then
	    # as directory, then fall back to displaying a 404.
	    try_files $uri $uri/ =404;
    }
}

服務啓動/停止:

uwsgi --ini uwsgi.ini # 啓動
uwsgi --reload uwsgi.pid  # 重啓
uwsgi --stop uwsgi.pid # 停止

nginx //啓動
nginx -s stop/quit //停止
nginx -s reload   //重啓加載配置

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章