documentRoot设置:
server {
listen 8099;
server_name localhost;
location / {
root www;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
其中两处红色的目录位置均需设置,设置完毕后,重启配置文件访问http://localhost:8099即可,端口号可自行设置。
反向代理:
server {
listen 8098;
server_name somename;
location / {
proxy_pass http://192.168.0.22:82;
proxy_set_header Host $host:$server_port;
}
}
访问http://somename:8098时即可访问到http://192.168.0.22:82内容。
虚拟主机设置:
server {
listen 8234;
server_name ngsck;
location / {
root D:/xampp/htdocs/xxx;
index index.php index.html index.htm;
}
location ~ \.php$ {
root D:/xampp/htdocs/xxx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
负载均衡设置:
配置好两个站点test1与test2
test1为:http://192.168.0.22:81
test2为:http://192.168.0.22:82
upstream test {
server 192.168.0.22:81;
server 192.168.0.22:82 weight=2;
}
server {
listen 8096;
server_name domain;
location / {
proxy_pass http://test;
proxy_set_header Host $host:$server_port;
}
}
访问http://domain:8096时会访问test1或test2,其中test1与test2出现的频率是1:2,因为test2的weight值为2