Nginx 配置代理上网

浏览:
字体:
发布时间:2013-12-09 23:23:56
来源:
1. Nginx简介 Nginx是和Apache相似的, 以前实验室的网络是不受限制的, 而宿舍的网络很多国外网站都打不开, 宿舍和实验室都处于校园网, 这个就可以通过代理在宿舍通过实验室网络浏览网页. 这样利用Nginx忘了算是正向代理还是反向代理了????

2. 下面是修改了的配置文件
# /etc/nginx/nginx.conf

######################################################################### This is the main Nginx configuration file. ## More information about the configuration options is available on # * the English wiki - http://wiki.nginx.org/Main# * the Russian documentation - http://sysoev.ru/nginx/########################################################################
#----------------------------------------------------------------------# Main Module - directives that cover basic functionality## http://wiki.nginx.org/NginxHttpMainModule##----------------------------------------------------------------------
user nginx;worker_processes 1;
error_log /var/log/nginx/error.log;#error_log /var/log/nginx/error.log notice;#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;

#----------------------------------------------------------------------# Events Module ## http://wiki.nginx.org/NginxHttpEventsModule##----------------------------------------------------------------------
events { worker_connections 1024;}

#----------------------------------------------------------------------# HTTP Core Module## http://wiki.nginx.org/NginxHttpCoreModule ##----------------------------------------------------------------------
http { include /etc/nginx/mime.types; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on; #tcp_nopush on;
#keepalive_timeout 0; keepalive_timeout 65;
#gzip on; # # The default server # server {resolver 222.201.130.30; listen 82; server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / { proxy_pass http://$http_host$request_uri; }
error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; }
# redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ /.php$ { # proxy_pass http://127.0.0.1; #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ /.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}
# deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ //.ht { # deny all; #} }
# Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf;
}

3. 主要修改的地方目前现状:只有1个机器能上网(web),其他机器不能
方法:能上网的做一个代理web服务器中转,其他机器连接它即可。采用nginx

Nginx配置如下:

server{
resolver x.x.x.x;
listen 82;
location / {
proxy_pass http://$http_host$request_uri; }}
注意项:1. 不能有hostname2. 必须有resolver, 即dns,即上面的x.x.x.x,换成你们的DNS服务器ip即可3 . $http_host和$request_uri是nginx系统变量,不要想着替换他们,保持原样就OK。
查看dns方法cat /etc/resolv.conf
4. 代理使用在linux, 我记得在当时是用的chrome浏览器的一个插件, 填下代理服务器IP和端口就可以了.
在需要访问外网的机器上执行以下操作之一即可:1. export http_proxy=http://yourproxyaddress:proxyport2. gedit ~/.bashrc export http_proxy=http://yourproxyaddress:proxyportyourproxyaddress也就是你的Nginx服务器的ip了,proxyport就是上面配置中的82,可以根据自己的需要修改。

举例:
  1. worker_processes 1;
  2. master_process off;
  3. daemon off;
  4. #pid /var/run/nginx.pid;

  5. events {
  6. worker_connections 768;
  7. # multi_accept on;
  8. }

  9. http {
  10. include mime.types;
  11. default_type application/octet-stream;

  12. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  13. '$status $body_bytes_sent "$http_referer" '
  14. '"$http_user_agent" "$http_x_forwarded_for"';

  15. access_log /var/log/nginx/access.log;
  16. error_log /var/log/nginx/error.log;

  17. sendfile on;

  18. server {
  19. resolver 10.57.220.2;
  20. listen 82;
  21. access_log logs/host.access.log main;

  22. location / {
  23. proxy_pass http://$http_host$request_uri;
  24. }


  25. }
  26. }









>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();