nginx 负载均衡

2019-04-28  本文已影响0人  黑客不黑_

www.domain.com均衡到本机不同的端口,也可以改为均衡到不同的地址上。

http {
: upstream myproject {
: server 127.0.0.1:8000 weight=3;
: server 127.0.0.1:8001;
: server 127.0.0.1:8002;
: server 127.0.0.1:8003;
: }

: server {
: listen 80;
: server_name www.domain.com;
: location / {
: proxy_pass http://myproject;
: }
: }
}

nginx 转发

# 转发设置
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# 网站
location / {
# post 转发
if ($request_method = POST ) {
proxy_pass [http://127.0.0.1:51001](http://127.0.0.1:51001/);
}

# 不是 put post delete 转发
# limit_except PUT POST DELETE {
# proxy_pass [http://127.0.0.1:51001](http://127.0.0.1:51001/);
# }

try_files $uri $uri/ /index.html?$query_string;
}

# 文档
location /doc {
proxy_pass [http://127.0.0.1:51001](http://127.0.0.1:51001/);
}

error_page 404 $uri;

nginx 反向代理php

server {
        listen  80;
        server_name     ~^(www\.)?phpcollege.org$;
        root    /www/phpcollege/public;
        index index.php;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~* \.php$ {
            try_files       $uri = 404;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }

        error_page 404 $uri;
}
上一篇下一篇

猜你喜欢

热点阅读