nginx实现多个端口多开

nginx配置文件

#开启wws必须要加1
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
#开启wws必须要加2
#这里可以写多个ip地址
upstream websocket {
    server 120.78.20.86:445;  #这里可以是多个服务端IP(分多行),设置权重就可以实现负载均衡了
    server 120.78.20.86:8383;
}

#支持 wss 
#多个加多个server 3
server {
    listen 446 ssl;   #多个监听的安全端口
    server_name wwe.com; #域名
    #ssl on; 
    ssl_certificate   cert/2020/www.ve.com.pem;   #证书
    ssl_certificate_key  cert/2020/wlive.com.key;
    ssl_session_timeout 20m;
    ssl_verify_client off;
    location / {  
        proxy_pass http://120.78.20.86:8383;   #这里是转向wss的关键 4
        proxy_http_version 1.1;  
        proxy_set_header Upgrade $http_upgrade;  
        proxy_set_header Connection "Upgrade";  
    }  
}

server {
      #  listen       80;
        listen       443 ssl http2;
        server_name  www.yun-live.com;
        #ssl on;

     
        ssl_certificate   cert/2020/wn-live.com.pem;
        ssl_certificate_key  cert/2020/wwn-live.com.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!3DES:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #location / {
        #    proxy_pass http://127.0.0.1:80;
        #    #proxy_redirect off;
    #       proxy_set_header Host $host;
    #       proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    #   
        #               proxy_set_header X-Forwarded-Proto $scheme;
        #   
        #}
       
        root   /home/wwwroot/yunxc/public;
        index  index.php index.html index.htm;
        
        #location / {
        #    try_files $uri $uri/ /index.php?$query_string;
        #}
        #proxy_set_header           X-Forwarded-Proto  $scheme;
    
        location / {
            #proxy_set_header           X-Forwarded-Proto  $scheme;
            #root   /alidata/www/yunxc/public;
            #index  index.php index.html index.htm; 
        if ($host != 'www.yun-live.com') {
              rewrite ^/(.*)$ https://www.yun-live.com/$1 permanent;
        }
       
            if (!-e $request_filename) {
              rewrite  ^(.*)$  /index.php?s=/$1  last;
              break;
            }
        }
        location ~ .*\.(php|php5)?$
        {
               #fastcgi_pass  127.0.0.1:9001;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }

    location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
           #wss协议转发 
           #一个只要加这里就可以了 。两个在外面加个server 
location /wss {
        proxy_pass https://wwe.com:445;#代理到上面的地址去,
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

  }

位置:/usr/local/nginx/conf/vhost
修改配置位置
cd /usr/local/nginx/conf/vhost/

配置好重启nginx命令
重启nginx 因为是源码安装的所以重启就是:
cd /usr/local/nginx/sbin
现在位置 /alidata/server/nginx-1.4.4/sbin
./nginx -t :检查nginx配置文件是否有错误
./nginx -s reload :不停nginx服务载入新配置文件

注:
监听端口要在安全规则里面添加才可以使用

前端接收


你可能感兴趣的:(nginx)