Nginx configure proxy for Internet access

Source: Internet
Author: User
Tags sendfile
1 Nginx introduction Nginx is similar to Apache & amp; 20284;. in the past, the lab network was unrestricted, while many foreign websites in the dormitory could not be opened, and both the dormitory and lab were on the campus network, this allows you to browse the web page in the dormitory through the lab network. nginx introduction Nginx is similar to Apache. in the past, the lab network was unrestricted, while many foreign websites in the dormitory could not be opened, and both the dormitory and lab were on the campus network, this allows you to browse the web page through the lab network in the dormitory through the proxy. in this way, I forget whether it is a forward proxy or a reverse proxy ????

2. the following is the modified configuration file.
#/Etc/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 /########################################################################
# Modules # 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;

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

# Certificate # 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 $ response" $ 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/50 x.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. the current status of the main changes: only one machine can access the Internet (web), and other machines cannot
Method: a proxy web server can be used for Internet access, and other machines can connect to it. Nginx

The Nginx configuration is as follows:

Server {
Resolver x. x;
Listen 82;
Location /{
Proxy_pass http: // $ http_host $ request_uri ;}}
Note: 1. there cannot be hostname2. there must be a resolver, that is, dns, that is, the above x. x. x. x. replace it with your DNS server ip address. $ http_host and $ request_uri are nginx system variables. do not replace them. if they are the same, they are OK.
View dns methods cat/etc/resolv. conf
4. the proxy is used in linux. I remember using a plug-in the chrome browser at that time. just fill in the proxy server IP address and port.
1. export http_proxy = http: // yourproxyaddress: proxyport2. gedit ~ /. Bashrc export http_proxy = http: // yourproxyaddress: proxyportyourproxyaddress is the ip address of your Nginx server. proxyport is the 82 configured above and can be modified as needed.

Example:
  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. }









Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.