Nginx 反向代理

金鞍玉勒寻芳客,未信我庐别有春。这篇文章主要讲述Nginx 反向代理相关的知识,希望能为你提供帮助。


一、linux nginx 反向代理

server
listen 80;
server_name api.xxxx.com; #自己域名
access_log off;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/none.conf;
root /data/wwwroot/default/api.xxxx.com;

#error_page 404 = /404.html;
#error_page 502 = /502.html;

location~ /
proxy_pass http://127.0.0.1:3000; #换成自己IP


location ~ [^/]\\.php(/|$)

#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;

location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$
expires 30d;
access_log off;

location ~ .*\\.(js|css)?$
expires 7d;
access_log off;

location ~ /\\.ht
deny all;


重点代码:
location~ /
proxy_pass http://自己IP:3000;


 
二、windows  Nginx 反向代理 (环境phpStudy)例子:打开网址www.fncms.com转跳到www.baidu.com
server
listen80;
server_namewww.fncms.com ;
root"E:/phpStudy/WWW/fncms.fn321.cn";
location /
indexindex.html index.htm index.php;
proxy_pass http://www.baidu.com;
#autoindexon;

location ~ \\.php(.*)$
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_split_path_info^((?U).+\\.php)(/?.+)$;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_paramPATH_INFO$fastcgi_path_info;
fastcgi_paramPATH_TRANSLATED$document_root$fastcgi_path_info;
includefastcgi_params;


重点加了这句话:proxy_pass http://www.baidu.com;

【Nginx 反向代理】 
 

    推荐阅读