nginx not forward local port

This paper analyzes the wrong problem solving 502 centos nginx configuration does not take effect after the next port forwarding, and the emergence of

One: Problem description

After forwarded by nginx server configuration, can not achieve the intended purpose of forwarding, we assume that the virtual machine ip is 192.168.0.8, and a web application deployed by .net core within a virtual machine

One: Problem analog and environmental structures

1, the installation nginx, see nginx basic installation and use

2, installation .netcore, and deployment

3, detection http://192.168.0.8, and http://192.168.0.8:5000, ensure nginx default page and deployment of applications can access .netcore

4. Change the port forwarding configuration nginx

server{
    listen       80;
    server_name  localhost;
    location / { 
            proxy_pass  http://localhost:5000;
        }
}

5, the results of testing, you will find access http://192.168.0.8 Times 502 errors, Why is this so? Obviously direct access http://192.168.0.8:5000 is normal, why nginx forward after being given?

Second, analyze the reasons and solutions

1, based on the above problems, the agent connection re-read the following code:

{Server 
    the listen 80; 
    server_name localhost; 
    LOCATION / { proxy_pass HTTPS: //home.cnblogs.com; # forwarded to modify the blog Park 
        } 
}
            

  After modification, visit again http://192.168.0.8 You will find as you might expect, really forwarded to the blog garden, then it shows a problem, forwarding and port configuration nginx has nothing to do! ! !

  So why can be forwarded to an external address, instead of the internal address can not forward it? ? ?

  In fact, the main reason for user rights, and called Selinux a linux system configuration

2. Solution

Nginx modify configuration files

# vim /etc/nginx/nginx.conf

The first line read user root, the default is nginx or nobody, vary depending on the version, I use the default value is 1.17 nginx

Nginx reload configuration

# nginx -s reload

 

After modifying the configuration file, re-visit, you will find access http://192.168.0.8 forwarded to the correct address http://192.168.0.8:5000

But sometimes after modifying the configuration file is still valid, need to Selinux disabled, the specific method is: enter selinux config file directory modification

# cd /etc/selinux
# vim config

The SELINUX set to disabled, and then restart your virtual machine reboot

After the above two-step nginx not forward local port issues will be completely resolved

 

Guess you like

Origin www.cnblogs.com/hanfeige/p/11387716.html