Nginx cannot jump to the specified root directory correctly when accessing a URL

Time:2020-2-7

Recently, the company’s project procurement system has been almost developed. My colleagues asked me to help deploy it after testing. After the jar package was docker, there was a problem when my colleagues configured nginx.

Except for the different domain names when configuring nginx, others are all the same. When visiting at this time, you will jump to the page of another project.

For example, to visit c.company.com, but skip to a.company.com, although the domain name is still c.company.com.

I can’t think of her sister. First, I used. / nginx – t to check whether there is a problem with the configuration. The result is correct.

Then. / nginx – s reload, check the error log of nginx and find out:

2019/11/29 13:47:35 [notice] 19479#0: signal process started
2019/11/29 13:47:35 [emerg] 3048#0: bind() to 0.0.0.0:9000 failed (98: Address already in use)
2019/11/29 13:47:35 [emerg] 3048#0: bind() to 0.0.0.0:9000 failed (98: Address already in use)
2019/11/29 13:47:35 [emerg] 3048#0: bind() to 0.0.0.0:9000 failed (98: Address already in use)
2019/11/29 13:47:35 [emerg] 3048#0: bind() to 0.0.0.0:9000 failed (98: Address already in use)
2019/11/29 13:47:35 [emerg] 3048#0: bind() to 0.0.0.0:9000 failed (98: Address already in use)
2019/11/29 13:47:35 [emerg] 3048#0: still could not bind()

Failed to find 9000 port binding.
This port number is a service port. How does it relate to nginx?

In fact, I didn’t read the log first, because the configuration is consistent with the test environment, and I don’t know what causes the root directory jump failure:

For example, the root directory of a.company.com is / A,
c. The root directory of company.com is / C. when I want to visit c.company.com, I can see through the nginx log that the access path is / A / index.html.

Why is this problem?

In fact, it has something to do with the above port. In the conf.d directory of my nginx, there are three configuration files:

a.conf
b.conf
c.conf

Among them, c.conf is the configuration of the new project. The above port binding failure is in b.conf. There is a problem with the SSL configuration. I don’t know why it’s not 443, but 9000. After you change it to 443, you can access it normally.

Summarize the reasons why the system will return to normal after modification:
1. Because there is no problem with the syntax of the configuration, using. / nginx – t will not detect the problem.

2. Because the configuration port error is in b.conf, b.conf just can’t use HTTPS, which doesn’t affect the use of HTTP, so no problem has been found

3. The reason why visiting c.company.com will jump to the page of a.company.com is that there is something wrong with b.conf, and nginx can’t load the next configuration file correctly, because the domain name resolution of a.company.com and c.company.com is on the same host, and the DNS resolution is waiting to be resolved to the current host, but the configuration of c.conf can’t be found correctly, so it can only be added by default It is loaded to the first configuration file a.conf, resulting in the access to C but skipping to the login page of A.

Nginx should be loaded in sequence when loading configuration. Once there is a problem with a configuration file, the following configuration file to be loaded will not be loaded correctly.

If you have any questions, welcome to discuss