About forward and reverse proxy
https://www.cnblogs.com/ysocean/p/9392908.html#_label0
The core part actually does the mapping of the local domain name, and proxy to the product homepage address http://192.168.56.1:10200/ by monitoring port 80 (default) of gulimall.com
The following is a detailed analysis and steps
1. Configure domain name mapping
The hosts file under C:\Windows\System32\drivers\etc can also be modified
Here we use a software switchHosts to modify the mapping, the download link is as follows
https://blog.csdn.net/JavaCoder_juejue/article/details/112760697
Create a new local plan, and then enter the corresponding mapping application
Originally accessed kibana in the virtual machine
Now access kibana in the virtual machine
Set nginx to start and start automatically
Last login: Sun Jan 17 12:53:56 2021 from 192.168.56.1
[root@10 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85e5c45a30da nginx:1.10 "nginx -g 'daemon of…" 4 weeks ago Exited (255) 3 weeks ago 0.0.0.0:80->80/tcp, 443/tcp nginx
6919debe7c73 elasticsearch:7.4.2 "/usr/local/bin/dock…" 4 weeks ago Up 4 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
fda06f05a0a0 kibana:7.4.2 "/usr/local/bin/dumb…" 4 weeks ago Up 4 hours 0.0.0.0:5601->5601/tcp kibana
69e789223ef0 redis "docker-entrypoint.s…" 4 weeks ago Up 4 hours 0.0.0.0:6379->6379/tcp redis
7c3556ac5cf1 mysql:5.7 "docker-entrypoint.s…" 4 weeks ago Up 4 hours 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
[root@10 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6919debe7c73 elasticsearch:7.4.2 "/usr/local/bin/dock…" 4 weeks ago Up 4 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
fda06f05a0a0 kibana:7.4.2 "/usr/local/bin/dumb…" 4 weeks ago Up 4 hours 0.0.0.0:5601->5601/tcp kibana
69e789223ef0 redis "docker-entrypoint.s…" 4 weeks ago Up 4 hours 0.0.0.0:6379->6379/tcp redis
7c3556ac5cf1 mysql:5.7 "docker-entrypoint.s…" 4 weeks ago Up 4 hours 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
[root@10 ~]# docker update nginx --restart=always
nginx
[root@10 ~]# docker start nginx
nginx
[root@10 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85e5c45a30da nginx:1.10 "nginx -g 'daemon of…" 4 weeks ago Up 3 seconds 0.0.0.0:80->80/tcp, 443/tcp nginx
6919debe7c73 elasticsearch:7.4.2 "/usr/local/bin/dock…" 4 weeks ago Up 4 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
fda06f05a0a0 kibana:7.4.2 "/usr/local/bin/dumb…" 4 weeks ago Up 4 hours 0.0.0.0:5601->5601/tcp kibana
69e789223ef0 redis "docker-entrypoint.s…" 4 weeks ago Up 4 hours 0.0.0.0:6379->6379/tcp redis
7c3556ac5cf1 mysql:5.7 "docker-entrypoint.s…" 4 weeks ago Up 4 hours 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
[root@10 ~]#
2. Test access to nginx
You can see that visiting http://gulimall.com/ actually visited the homepage of nginx
3. Modify the nginx configuration to achieve proxy access to the product homepage
Specify the file we want to modify
[root@10 ~]# cd /
[root@10 /]# ls
bin boot dev -e etc home lib lib64 media mnt mydata opt proc root run sbin srv swapfile sys tmp usr -v vagrant var
[root@10 /]# cd mydata/nginx/c
-bash: cd: mydata/nginx/c: No such file or directory
[root@10 /]# cd mydata/nginx/conf/
[root@10 conf]# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
[root@10 conf]# cat nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
[root@10 conf]# cd conf.d/
[root@10 conf.d]# ls
default.conf
View the IP of the intermediate network card or the IP of the virtual machine
All visited successfully
[root@10 conf.d]# cp default.conf gulimall.conf
[root@10 conf.d]# ls
default.conf gulimall.conf
[root@10 conf.d]# vi gulimall.conf
server {
listen 80;
server_name gulimall.com;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
proxy_pass http://192.168.56.1:10200;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
"gulimall.conf" 44L, 1071C written
[root@10 conf.d]# docker restart nginx
nginx
[root@10 conf.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85e5c45a30da nginx:1.10 "nginx -g 'daemon of…" 4 weeks ago Up 22 seconds 0.0.0.0:80->80/tcp, 443/tcp nginx
6919debe7c73 elasticsearch:7.4.2 "/usr/local/bin/dock…" 4 weeks ago Up 5 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
fda06f05a0a0 kibana:7.4.2 "/usr/local/bin/dumb…" 4 weeks ago Up 5 hours 0.0.0.0:5601->5601/tcp kibana
69e789223ef0 redis "docker-entrypoint.s…" 4 weeks ago Up 5 hours 0.0.0.0:6379->6379/tcp redis
7c3556ac5cf1 mysql:5.7 "docker-entrypoint.s…" 4 weeks ago Up 5 hours 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
[root@10 conf.d]#
Access test
The reverse proxy is successful, it will be a little troublesome, do different services have to configure reverse proxy in nginx, and then prepare to reverse proxy to the gateway