nginx和https配合swoole4反向代理部署

服务器需要进行nginx反向代理部署,静态资源可以通过http或https方式访问

但是不是静态资源的,需要代理到swoole内置的http服务器上去,配置如下

upstream nodenuxt {
    server 127.0.0.1:9501; 
}
server
{
    listen 80;
    listen 443 ssl http2;
    server_name  www.xxx.com;
    root /www/wwwroot/www.xxx.com/public;
    index index.html index.php index.htm default.php default.htm default.html;
    #添加响应头
    add_header renderer "webkit";
    add_header Content-Security-Policy "upgrade-insecure-requests";
    add_header X-UA-Compatible "IE=edge,chrome=1";
    #升级HTTPS
    set $http 0;
    if (!-f $request_filename) {
     	set $http "${http}1";
  	}
    if ($scheme = http ) { 
	    set $http "${http}2";
	}
    if ($http = "012"){
       return 301 https://$host$request_uri; 
	}
    #限制每IP的PHP请求并发数量为30个
    limit_conn perip 30;
    limit_conn perserver 50;
    #告诉浏览器 本宝宝域名不允许被 iframe
	add_header X-Frame-Options SAMEORIGIN;
    #配置ssl文件配置
    ssl_certificate /www/ssl/mzhua/common.pem;
    ssl_certificate_key /www/ssl/mzhua/common.key;
    ssl_session_timeout 10m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-
    SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    
    location / {
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Scheme $scheme;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Nginx-Proxy true;
        proxy_cache_bypass $http_upgrade;
        if (!-f $request_filename) {
          proxy_pass http://nodenuxt; #反向代理
        }
    }
    
     
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log off;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log off; 
    }
    access_log  /www/wwwlogs/video.mzhua.com.log;
    error_log  /www/wwwlogs/video.mzhua.com.error.log;
}

 

你可能感兴趣的:(PHP,swoole)