Nginx 配置反向代理
有时候在访问国外被墙的网站的时候是非常郁闷的,比如某搜索引擎,虽然可以访问香港的站点,但会出现间歇性的中断,在条件允许的情况下是可以将国外的VPS做反向代理,方便自己搜索。
Nginx做反向代理是非常不错的选择,虽然Apache也有对应的功能,但现在最常用的还是使用Nginx来做反向代理。
自己弄的VPS是采用LNMP自动安装的程序环境,并没有对其做过多的配置。
server { listen 80; server_name yotodo.net www.yotodo.net; index index.html index.htm index.php default.html default.htm default.php; root /home/www.yotodo.net; include none.conf; # location ~ .*.(php|php5)?$ # { # fastcgi_pass unix:/tmp/php-cgi.sock; # fastcgi_index index.php; # include fcgi.conf; # } # # location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ # { # expires 30d; # } # # location ~ .*.(js|css)?$ # { # expires 12h; # } location /{ proxy_pass http://www.google.com/; # proxy_pass https://twitter.com/sessions; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } log_format www.yotodo.net '$remote_addr - $remote_user [$time_local] $request ' '$status $body_bytes_sent $http_referer ' '$http_user_agent $http_x_forwarded_for'; access_log /home/wwwlogs/www.yotodo.net.log www.yotodo.net; }
以上是我直接建立的Nginx虚拟机,并配置好对应的代理服务。由于默认建立的虚拟机配置存在一些静态文件缓存配置,我们使用反向代理的话,就没有必要用到缓存,直接把对应的行注释掉即可。
实际新增的代码如下:
location /{ proxy_pass http://www.google.com/; # proxy_pass https://twitter.com/sessions; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
–ENDOF–