Nginx 反向代理

Posted Q神

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;

Nginx

 

二、windows Nginx 反向代理 (环境phpStudy)

例子:打开网址www.fncms.com转跳到www.baidu.com

server 
listen 80;
server_name www.fncms.com ;
root "E:/phpStudy/WWW/fncms.fn321.cn";
location /
index index.html index.htm index.php;
proxy_pass http://www.baidu.com;
#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;

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

Nginx

 

 

以上是关于Nginx 反向代理的主要内容,如果未能解决你的问题,请参考以下文章

用nginx反向代理的问题?(详内)

Nginx简单粗暴的反向代理教程

nginx反向代理数据传输能提高数据响应么?

Nginx 最全操作——nginx反向代理(5)

Nginx 如何设置反向代理

如何使用nginx设定反向代理