nginx 反向代理apache2、php-fpm、uwsgi配置

一、nginx反向代理配置样例

#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  4096;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  180;
    client_max_body_size 500m;
    #gzip  on;
    #反向代理到Apache2
    server
    {
        listen 80;
        server_name eblog.com;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8888;
        }
    }
    #反向代理,Apache2通过mod_php模式执行php代码
    server
    {
            listen 80;
            server_name shop.com test.com;
            location / {
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header REMOTE-HOST $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_pass http://127.0.0.1:8888;
            }
    }
    #反向代理,并使用php-fpm进程模式执行php代码
    server{
        listen  80;
        server_name api.com;
        index index.php;
        root /var/www/yaf_api/public;
        if (!-e $request_filename) {
            rewrite ^/(.*)  /index.php?$1 last;
        }

        location ~ .php$ {
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        access_log /var/log/yaf_api/yaf.api.log;
    }

    #反向代理到python
    server 
    {
            listen       80;
            server_name  webchat.com;

            location / {           
            root /var/www/webchat;
                include  uwsgi_params;
                uwsgi_pass  127.0.0.1:9090;              #必须和uwsgi中的设置一致
                uwsgi_param UWSGI_SCRIPT webchat.wsgi;  #入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录
                uwsgi_param UWSGI_CHDIR /var/www/webchat;       #项目根目录
                index  index.html index.htm;
                client_max_body_size 35m;
            }
    }

    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  test.com;
        access_log logs/https-access.log;
        error_log logs/https-error.log;
        ssl on;
        #HTTPS服务端
        ssl_certificate      /home/web/myssl/server-cert.pem;
        ssl_certificate_key  /home/web/myssl/server-key.pem;
        #HTTPS双向验证,客户端密钥设置
        ssl_client_certificate /home/web/myssl/ca-cert.pem;
        ssl_verify_client on;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
        ssl_prefer_server_ciphers on;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
             root   html;
        }
        location / {
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header REMOTE-HOST $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_pass http://127.0.0.1:8888
        }
    }

}

转自 https://blog.csdn.net/Just_shunjian/article/details/78852808

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值