Nginx reverse proxy is used as intranet domain name forwarding _nginx

Source: Internet
Author: User
Tags http request nginx reverse proxy

Because the company intranet has more than one server HTTP service to map to the company's external network static IP, if the port map with the route to do, you can only one intranet server 80-port map to the extranet 80 ports, the other server 80 ports can only map to the outside of the network of 80 ports. Non-80-port mapping in the access time to the domain name plus port, more trouble. And the company portal route can only do 20 port mappings.

Definitely not enough later.

Then found that you can build a Nginx reverse proxy server in the intranet, Nginx 80 of the reverse proxy server mapped to 80 of the extranet IP, so the HTTP request to the domain name of the company extranet IP will be sent to the Nginx reverse proxy server, Using Nginx reverse proxy to forward different domain names to the ports of different machines in the intranet, the effect of "automatically forwarding the specific port according to the domain name to the corresponding server" has been played, and the router's port mapping is only "automatically forwarded to the specific port of the corresponding server according to the different ports".

The objective of this experiment is to do: in the browser input xxx123.tk can access to the intranet machine 192.168.10.38 3000 port, input xxx456.tk can access to the intranet machine 192.168.10.40 80 port.

Vim nginx.conf worker_processes 1;
Error_log Logs/error.log;
PID Logs/nginx.pid;
Worker_rlimit_nofile 65535;
  events {use Epoll;
Worker_connections 65535;
  } http {include mime.types;
  Default_type Application/octet-stream;
  include/usr/local/nginx/conf/reverse-proxy.conf;
  Sendfile on;
  Keepalive_timeout 65;
  gzip on; Client_max_body_size 50m;
  #缓冲区代理缓冲用户端请求的最大字节数, can be understood as saving to the local and then passed to the user client_body_buffer_size 256k;
  Client_header_timeout 3m;
  Client_body_timeout 3m;
  Send_timeout 3m; Proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间 (Agent connection timeout) Proxy_read_timeout 300s;
  #连接成功后, back-end server response time (proxy receive timeout) Proxy_send_timeout 300s; Proxy_buffer_size 64k; #设置代理服务器 (Nginx) to save the buffer size of user header information Proxy_buffers 4 32k; #proxy_buffers缓冲区, the average page below 32k, so set proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2) proxy_temp_file_write_size 64k; #设定缓存文件夹大小, greater than this value, the request will be passed from the upstream server without buffering to disk proxy_ignore_client_abort on;
    #不允许代理端主动关闭连接 server {Listen 80;
    server_name localhost; Location/ {root HTML;
    Index index.html index.htm;
    } error_page 502 503 504/50x.html;
    Location =/50x.html {root html;
  }} server {listen 80;
  server_name xxx123.tk;
    Location/{proxy_redirect off;
    Proxy_set_header Host $host;
    Proxy_set_header X-real-ip $remote _addr;
    Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
  Proxy_pass http://192.168.10.38:3000;
} Access_log Logs/xxx123.tk_access.log;
  } server {Listen 80;
  server_name xxx456.tk;
    Location/{proxy_redirect off;
    Proxy_set_header Host $host;
    Proxy_set_header X-real-ip $remote _addr;
    Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
  Proxy_pass http://192.168.10.40:80;
} Access_log Logs/xxx456.tk_access.log;
 }

Enter the xxx123.tk in the browser to access the intranet server 192.168.10.38 3000 port, enter the xxx456.tk access to 192.168.10.40 80 port role. If you want to load balance the back-end machine, like the following configuration can be distributed to the nagios.xxx123.tk request to the Intranet 131 and 132 of the two machines do load balancing.

Upstream Monitor_server {
  server 192.168.0.131:80;
    Server 192.168.0.132:80;
}
Server
{
  listen;
  server_name nagios.xxx123.tk;
  Location/{
    proxy_redirect off;
    Proxy_set_header Host $host;
    Proxy_set_header x-real-ip $remote _addr;
    Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
    Proxy_pass http://monitor_server;
  }
  Access_log logs/nagios.xxx123.tk_access.log;
}

The following paragraph was not previously configured, and occasionally 504 Gateway timeout was present on the visit

  Proxy_connect_timeout 300s;  Proxy_read_timeout 300s;
  Proxy_send_timeout 300s;
  Proxy_buffer_size 64k;
  Proxy_buffers 4 32k;
  Proxy_busy_buffers_size 64k;
  Proxy_temp_file_write_size 64k;
  Proxy_ignore_client_abort on;

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.