nginx Extranet Access Site Configuration Operation
- 2021-08-21 22:00:26
- OfStack
Background:
Site is front-end separation: vue+springboot
Front-end intranet address: 192.168. 1.10:81
API Intranet Address: 192.168. 1.12: 8080
External domain name: abc. ab. com External IP: 10.114. X. X
Requirements:
The site can be accessed through the domain name and the static resources of the site can be accessed and the API request data can be accessed
Scheme 1: (Premise: Extranet domain name mapping server Extranet IP)
1. nginx configures domain name listening and accessing static resources
2. Here comes the point! ! ! The address of static resource request API is changed from 192.168. 1.12: 8080 to domain name access (abc. ab. com: 8080)
Just restart nginx
Other schemes will be put up after bloggers verify them! !
Supplementary knowledge: Realize reverse proxy with nginx, and realize the service of external network accessing internal network
Environment background, server is Ubuntu:
One server A that can connect public network and intranet, the address of IP of public network is 61.174. ×. ×, and the other server B of intranet is equipped with jenkins service, and the address of IP of intranet is 192.168. 3.12
Operation steps:
Installing nginx on A
sudo apt-get install nginx
After installation, go to the/etc/nginx/sites-enabled directory, open the files in the directory, change the default port number to 8085,
Then enter the/etc/nginx/conf. d directory and create a new file, jenkins. conf, with the following contents:
server{
listen 8085;
server_name 61.174.171.61;
location /{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://192.168.3.12:8080;
proxy_redirect off;
}
Then execute
sudo nginx -t
sudo nginx -s reload
If an error occurs:
nginx: [error] invalid PID number "" in "/run/nginx.pid"
Execute the
sudo nginx -c /etc/nginx/nginx.conf
Then visit 61.174. 171.61: 8085 on the public network to access the jenkins service on the intranet.