Home  >  Article  >  Operation and Maintenance  >  How to do reverse proxy in nginx

How to do reverse proxy in nginx

藏色散人
藏色散人Original
2019-06-12 10:45:405354browse

How to do reverse proxy in nginx

How does nginx do a reverse proxy?


The network structure is as shown above.

Maybe you only have one public IP address. But you have a website on your intranet If you need to map to the external network and do not want to add other non-80 ports, you can directly use nginx as a reverse proxy.

First, configure the nginx.conf file.

http {
    include                 mime.types;
    default_type            application/octet-stream;
    client_max_body_size    8m;    ################################################################################
    include /usr/local/u-mail/config/nginx/reverse-proxy.conf;    ################################################################################
    #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             logs/access.log  main;
    sendfile                on;    #tcp_nopush             on;
    #keepalive_timeout      0;
    keepalive_timeout       65;    #gzip                   on;    upload_progress         proxied 1m;    ###############################################################################    gzip             on;    #client_max_body_size    50m;    client_body_buffer_size 256k;
    client_header_timeout   3m;
    client_body_timeout     3m;
    send_timeout            3m;
    proxy_connect_timeout   300s;
    proxy_read_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;    
     
    ###############################################################################
    include                 vhost/*.conf;
}

The above configuration file refers to the /usr/local/u-mail/config/nginx/reverse-proxy.conf;

configuration file. You can use relative paths for this filling, or The absolute path can be filled in. For the sake of demonstration, the absolute path will be filled in directly.

Then look at the referenced configuration file information.


As above. Then restart the nginx service directly. Check whether it is normal and whether there is any error. If there is no error message, it is OK. If you have multiple websites, you can set multiple server sections in reverse-proxy.conf. .One website and one section. Separate them. It will be convenient to check next time.

For more Nginx related knowledge, please visit the Nginx Usage Tutorial column!

The above is the detailed content of How to do reverse proxy in nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn