1、域名映射
1、下载switchHosts工具
该工具主要是用于添加或修改域名功能
2、找到hosts文件,并取消只读权限

3、打开switchHosts工具,添加域名与IP地址的映射关系

4、验证,使用域名和IP访问的效果一样,达到了域名映射的功能

2、修改nginx配置
1、进入到以下目录
# cd /home/nginx/conf/conf.d/
# cp default.conf gulimall.conf
# vim gulimall.conf
2、修改gulimall.conf配置文件
server {
listen 80;
server_name gulimall.com;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://192.168.136.1:8088;
}
#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;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
注:http://192.168.136.1:8088 ,是首页地址

保存退出后,重启nginx
docker restart nginx
2、访问gulimall.com

这样就实现了通过映射域名,再访问域名跳转到nginx服务后,nginx内部再做一次跳转到首页的地址。
3、nginx负载均衡到网关
1、进入nginx.conf主配置文件中,添加网关负载配置

添加以下配置:
upstream gulimall{
server 192.168.136.1:88;
}
2、进入conf.d目录下,修改gulimall.conf配置
gulimall:就是在nginx.conf配置文件中网关的配置服务代理

nginx代理给网关的时候,会丢失请求的host信息,就需要修改nginx配置的路径映射规则
修改gulimall.conf,添加以下配置信息
location / {
proxy_set_header Host $host;
}

3、网关路由配置
- id: gulimall_host_route
uri: lb://gulimall-product
predicates: # 什么情况下路由给它
- Host=**.gulimall.com,item.gulimall.com
4、验证




3万+

被折叠的 条评论
为什么被折叠?



