How to configure nginx proxy forwarding

(*-*)浩
Release: 2019-07-20 15:43:58
Original
68862 people have browsed it

How to configure nginx proxy forwarding

Nginx is a powerful server, you can configure multiple servers, a server is a server

server {
      listen       80;
      server_name  *.yourdomain.com;

   ....
}
Copy after login

The proxy forwarding is the location under the server Configure

server {
   // 服务器配置
   location  / {
   // ...... 代理配置
   }
}
Copy after login

Common Nginx proxy configuration

upstream my_server {                                                         
    server 10.0.0.2:8080;                                                
    keepalive 2000;
}
server {
    listen       80;                                                         
    server_name  10.0.0.1;                                               
    client_max_body_size 1024M;

    location /my/ {
        proxy_pass http://my_server/;
        proxy_set_header Host $host:$server_port;
    }
}
Copy after login

Through this configuration, access the nginx address http://10.0.0.1 :80/my requests will be forwarded to the my_server service address http://10.0.0.2:8080/

It should be noted that if configured as follows:

upstream my_server {                                                         
    server 10.0.0.2:8080;                                                
    keepalive 2000;
}
server {
    listen       80;                                                         
    server_name  10.0.0.1;                                               
    client_max_body_size 1024M;

    location /my/ {
        proxy_pass http://my_server;
        proxy_set_header Host $host:$server_port;
    }
}
Copy after login

Then, a request to access the nginx address http://10.0.0.1:80/my will be forwarded to the my_server service address http://10.0.0.2:8080/my. This is because if the proxy_pass parameter does not contain the path of the url, the path identified by the location pattern will be used as an absolute path.

For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template