python写网站 linux_linux下利用nginx部署python网站

首先目标机器需要安装python nginx uwsgi,其次,需要给Nginx写配置文件,大体内容如下,

具体内容可见 http://blog.cn2p.com/web-server/nginx-uwgsi-python.html 比较具体。

server {

#修改监听端口

listen 80;

#修改域名

server_name zone4j.com;

#301重定向

if ($host != ‘zone4j.com’) {

rewrite ^/(.*)$ http://zone4j.com/? permanent;

}

#charset koi8-r;

#access_log /var/log/nginx/log/host.access.log main;

location / {

include uwsgi_params;

uwsgi_pass 127.0.0.1:8023;

}

#静态内容nginx直接处理

location ~.*(html|css|js|gif|jpg|jpeg|png|bmp|ico|txt)$ {

root /var/www/html;

}

#404

error_page 404 /404.html;

location = /404.html {

root /var/www/html;

}

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

}

然后用Uwsgi执行server.py 文件(必须在项目的根目录文件下),命令如下 uwsgi_python3 -s 0.0.0.0:8080 --file server文件的绝对路径

经验分享 程序员 微信小程序 职场和发展