nginx怎样做反向代理服务器
废话不多说,直接贴配置文件
server {
listen 80;
server_name b.ildd.cc;
#charset koi8-r;
#access_log /usr/local/nginx/logs/host.access.log main;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
location / {
proxy_pass http://172.17.0.3:80;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~* \.php$ {
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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
重点内容在加黑的位置,这只是简单的一些设置。访问b.ildd.cc自动跳转到172.17.0.3.
如果需要做负载均衡的话需要在server的上面添加:
upstream test {
server 172.17.0.3:80;
server 172.17.0.4:80;
}
location / {
proxy_pass http://test;
index index.php index.html index.htm;
}
上面意思为172.17.0.3和172.17.0.4做负载均衡
以上内容纯属原创,翻版必究!不明白的可以加QQ群讨论:955496382
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。






