The cause of the incident was the external mapping port access problem of GitLab within the company. Using port 80/443 in the internal network to access normally, using a non-80 port to access the home page will automatically jump to port 80. Manual port access is normal, but this is extremely affect the user experience.
1. Background description
The intranet uses a container to build a GitLab
platform, the internal Nginx
port is 8081, and IP+Port
the access is normal by using the form. After deploying the reverse management from other machines Nginx
, the access using the domain name is also normal, but the reverse management port is changed to non- Port 80/443, when accessing the home page through the form of domain name and port, it will jump to port 80, resulting in access failure, as shown below:
http://git.example.com:1443 — > http://git.example.com
After manually adding the port to the redirected URL, the access is normal again, so it is guessed that there may be a Nginx
configuration problem.
2. Problem solving
1. The cause of the problem
Nginx
Due to the loss of the port, Nginx
the port information was not correctly transmitted to the backend, and the configuration was not correctNginx
2. Problem solving
server {
listen 8888;
server_name localhost;
location / {
proxy_set_header Host $host:$server_port; 这一行是关键
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
proxy_set_header Host $host:$server_port;
This line is the key, must be set to get the real port.