美文网首页
nginx 配置技巧

nginx 配置技巧

作者: DimonHo | 来源:发表于2018-11-09 08:52 被阅读15次

    需求一、域名映射

        server{
            listen        80;
            server_name  www.dimonho.com;
            location / {
                proxy_pass http://192.168.1.92:18080;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 100m;
            }
        }
    

    需求二、将dimonho.com自动转发到www.dimonho.com

        server{
            listen        80;
            server_name  dimonho.com www.dimonho.com;
            if ($host = 'dimonho.com'){
                rewrite ^/(.*)$ http://www.dimonho.com/$1 permanent;
            }
            location / {
                proxy_pass http://192.168.1.92:18080;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 100m;
            }
        }
    
    

    需求三、www.dimonho.com集群负载均衡

        upstream  dh.com {
            server 192.168.1.92:18080  weight=1;
            server 192.168.1.94:18080  weight=2;
        }
        server{
            listen        80;
            server_name  dimonho.com www.dimonho.com;
            if ($host = 'dimonho.com'){
                rewrite ^/(.*)$ http://www.dimonho.com/$1 permanent;
            }
            location / {
                proxy_pass http://dh.com;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 100m;
            }
        }
    
    

    相关文章

      网友评论

          本文标题:nginx 配置技巧

          本文链接:https://www.haomeiwen.com/subject/evlnxqtx.html