nginx 实用案例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 实用案例相关的知识,希望对你有一定的参考价值。

nginx SSL Proxy:

upstream nexus {
    server 127.0.0.1:8081 weight=1 max_fails=2 fail_timeout=30s;
}   
server {
    listen 443 ssl;
    server_name nexus.******.com;
    #ssl on;
    ssl_certificate ssl/1_nexus.******.com_bundle.crt;
    ssl_certificate_key ssl/2_nexus.******.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
    ssl_prefer_server_ciphers on;
    location / {
             proxy_pass http://nexus;
             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-Forwarded-Proto   https;
             client_max_body_size 300M;
    }
}
server {
        listen 80;
        server_name nexus.******.com;
        rewrite ^(.*)$  https://$host$1 permanent;
}

Nginx grpc Proxy:

server {
        listen 8080;
        server_name nexus.umarkcloud.com;

         if ( $request_uri = / ) {
            return 301 http://$host:8080/grpc-precompiled-binaries/node/grpc/;
         }

        location  ~ /grpc-precompiled-binaries/node/grpc/(.*$) {
                proxy_pass  https://npm.taobao.org/mirrors/grpc/$1;
                proxy_redirect          off;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location ~ /mirrors/grpc/.*$ {
                proxy_pass https://npm.taobao.org;
        }
}

以上是关于nginx 实用案例的主要内容,如果未能解决你的问题,请参考以下文章

Android 实用代码片段

asp.net页面实用代码片段

实用代码片段

超实用的php代码片段

分享几个实用的代码片段(附代码例子)

分享几个实用的代码片段(附代码例子)