时间:2020-02-02加入收藏
2、全站代理配置(首页不代理)server {
listen 80;
server_name www.test1.com ;
root "D:\PHP\WWW\nginx.com";
location / {
index index.html index.htm index.php;
#autoindex on;
#反向代理配置
proxy_pass http://www.test2.com
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
3、目录代理配置server {
listen 80;
server_name www.test1.com ;
root "D:\PHP\WWW\nginx.com";
#配置首页不代理
location = / {
index index.html index.htm index.php
}
location / {
index index.html index.htm index.php;
#autoindex on;
#反向代理配置
proxy_pass http://www.test2.com
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
4、指定类型文件代理配置server {
listen 80;
server_name www.test1.com ;
root "D:\PHP\WWW\nginx.com";
#目录代理 news目录代理 www.test2.com
location /news/ {
proxy_pass http://www.test2.com
}
location / {
index index.html index.htm index.php;
#autoindex on;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
nginx服务器的指定文件类型反向代理配置时,只配置一种文件类型时,重启服务器的时候报错,导致服务器重启失败,不知道是配置的时候出了点小差错还是这里必须两种以上的类型。server {
listen 80;
server_name www.test1.com ;
root "D:\PHP\WWW\nginx.com";
#指定文件类型代理配置(.shtml、.htm 类型文件代理 www.test2.com)
location ~ .*\.(shtml|htm)$ {
proxy_pass http://www.test2.com
}
location / {
index index.html index.htm index.php;
#autoindex on;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
location ~* \.(html)$ {
root /www/wwwroot/;
index index.html;
}
location = / {
proxy_pass http://127.0.0.1/index.html;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
TGA: 技巧