nginx 反向代理

# 反向代理 Apachephp

nginx.confhtml

server
{
            listen       80;
            server_name  www.sui.cn lucky.sui.cn;

   location / {            
            proxy_pass              http://127.0.0.1:8080;              
            proxy_redirect          off;        
            proxy_set_header Host $host;       
            proxy_set_header X-Real-IP $remote_addr;       
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;           
            } 
}

httpd.confnode

#在httpd.conf中 添加 (/etc/httpd/conf/httpd.conf)

<virtualhost *:8080>
    ServerName  www.sui.cn
    ServerAlias  www.sui.cn lucky.sui.cn
    DocumentRoot  /www/one
    DirectoryIndex index.php index.html
    <Directory /www/one>
    Options +Includes +FollowSymLinks -Indexes
    AllowOverride All
    Order Deny,Allow
    Allow from All
    </Directory>
</virtualhost>

 

經過域名反向代理:nginx

upstream myapp {
    # server www.sui6666.com:8888 weight=1; # 應用服務器1
    # server 121.65.111.236:8888 weight=3;
     server www.test.com;
}

server
{
            listen       80;
            server_name  sui1.lucky.com;
 
   location / {           
             proxy_pass  http://myapp;
             proxy_set_header Host  www.test.com;       
            }
}

proxy_pass http://www.test.com;git

nginx會把 www.test.com;轉換成IP, 跟用IP直接訪問網站的效果同樣. 當網站設置了禁用IP訪問或一個IP有多個網站時, 訪問就會出錯.web

這時候就要設置 proxy_set_header的Host:vim

proxy_set_header Host www.test.com;;bash

這樣才能經過域名解析到具體的網站, nginx反向代理同一ip多nginx反向代理同一ip多個域名,給header加上host就能夠了個域名,給header加上host就能夠了服務器

 

反向代理gitlabwebsocket

nginx.conf

 server {
         listen      80;
     
         server_name  git.sui.net;

        location / {
            proxy_pass http://127.0.0.1:8080;
        }

       
    }

gitlab 修改默認ssh端口爲2222 ,使用git修改默認的ssh端口號(vim ~/.ssh/config)

        Host git.sui.net
    HostName git.sui.net
    User 28456049@qq.com
    port 2222
    IdentityFile ~/.ssh/git.sui.net_rsa    

 # 反向搭理wss

upstream wss_svr {
server 127.0.0.1:2346 weight=1;  #這裏能夠是多個服務端IP(分多行),設置權重就能夠實現負載均衡了(websocket 服務的端口,swoole,nodejs.go服務的websocket均可以)
}    

server {
        server_name  www.sui.com;
        root /tmmee/sad.cn/public;
        listen 443 ssl;
        ssl_certificate  /etc/fullchain.pem;
        ssl_certificate_key /etc/privkey.pem;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_stapling on;
        ssl_stapling_verify on;
        add_header Strict-Transport-Security max-age=15768000;
        # websocket 代理
        location /ws {
            proxy_redirect off;
            proxy_pass http://wss_svr;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

    location / {
        index  index.php index.html index.htm;
    }
    location ~ ^(.+\.php)(.*)$ {
        fastcgi_pass            127.0.0.1:9000;
        fastcgi_split_path_info       ^(.+\.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;

        include        fastcgi_params;
    }
}

websocket 地址: var wsUrl = "wss://www.sui.com/ws";

相關文章
相關標籤/搜索