nginx部署python应用

1.nginx下载地址http://nginx.org/en/download.html

2.nginx配置文件如下:#位于  /nginx/conf/nginx.conf

#user nobody;
worker_processes 1;

events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 185;

server {
listen 8088;#对外的端口
server_name localhost;

location /media/ {
alias D:/hujin/DMMS/static/;
expires 30d;
}
#静态资源
location /static/
{
alias D:/hujin/DMMS/static/;
expires 30d;
}

location / {
fastcgi_read_timeout 30m;#一般用于后台长时间处理时保持不断开
fastcgi_pass 127.0.0.1:8080;#python启动的地址和端口
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

3.启动python:

进入项目所以的路径

python manage.py runfcgi method=threaded host=127.0.0.1 port=8080

5.启动nginx(双击即可)

在浏览器中输入:localhost:8088即可看到你的项目了。这时你的项目可以在局域网里访问了

 

注意:nginx每次双击都会创建一个新的进程,所以在修改了配置文件后即可在任务管理器中把nginx的进程结束掉再启动新的,不然修改的就没用了

 

你可能感兴趣的:(python)