#设定虚拟主机配置
upstream fengzhanhai{
#负载均衡池
# ip_hash;
server 10.0.211.2 down weight=4 max_fails=2 fail_timeout=30s;
server 10.0.211.2:8080 weight=4 max_fails=2 fail_timeout=30s;
# server 10.0.211.3:8080 weight=4 max_fails=2 fail_timeout=30s;
# server 10.0.211.4:8080 weight=4 max_fails=2 fail_timeout=30s;
# server 192.168.202.81:8080 weight=2 max_fails=2 fail_timeout=30s;
server 192.168.202.82 weight=4 max_fails=2 fail_timeout=30s;
}
server {
#虚拟主机反向代理负载均衡池fengzhanhai的主机应用
listen 80;
server_name www.123.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
#当分发的后端业务宕机后无缝切换到pool中存活的业务之上
proxy_pass http://fengzhanhai;
#反向代理资源池
proxy_set_header Host www.123.com;
proxy_set_header X-Forwarded-For $remote_addr;
root html;
index index.html index.htm;
}
access_log logs/feng.log combined;
#访问日志
#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 {
root 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$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
4、 测试Nginx配置语法是否正常
5、 ./nginx –t
返回如下信息表示参数配置无误
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful