Nginx分发动态请求到不同项目

在同一台服务器当中,根据不同的域名将动态请求分发给Django和Flask两个项目:
在Nginx配置文件中配置两个server参数:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    # www.****.com
    server {
        listen       80;
        listen       [::]:80;
        server_name  www.****.com;
        root         /usr/share/nginx/html;


        charset     utf-8;
        access_log      /data/www/main-web/nginx_access.log;
        error_log       /data/www/main-web/nginx_error.log;
        client_max_body_size 75M;


         location /static {
             alias /data/www/main-web/statics;
         }

         location / {
             include     /etc/nginx/uwsgi_params;
             uwsgi_pass  127.0.0.1:9090;
         }

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
    # blog.****.com
    server {
        listen       80;
        listen       [::]:80;
        server_name  blog.****.com;
        root         /usr/share/nginx/html;


        charset     utf-8;
        access_log      /data/www/blog/nginx_access.log;
        error_log       /data/www/blog/nginx_error.log;
        client_max_body_size 75M;


         location /static {
             alias /data/www/blog/App/static;
         }

         location / {
             include     /etc/nginx/uwsgi_params;
             uwsgi_pass  127.0.0.1:5000;
         }

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

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

}

Flask项目对应的uwgsi.ini配置socket监听5000端口
Django项目对应的uwgsi.ini配置socket监听9090端口
服务器域名配置好 www.****.com和blog.****.com的解析(同一ip)

posted @   Bruce_JRZ  阅读(55)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示