【破案了,是我蠢了,配置网关的路由的时候,忘记重启网关的微服务了,好像一直重启的是其他的微服务,还一直很纳闷为啥不行】
今天在学习谷粒商城时,学到了nginx搭建域名访问环境,第一步的反向代理配置成功,可以使用gulimall.com访问到主页,但是在第二步的时候,要通过负载均衡转发请求到网关时,怎么都配置不好,按照视频里的配置都不行,网络上好像都没有说到有出现这个问题,看了很多前人写的笔记,也按照步骤来了,但是也是不行。目前是想访问gulimall.com是不行的,但是如果是访问gulimall.com/api/product/attrattrgrouprelation/list却能正常访问。访问gulimall.com时页面显示如下:
下面是我的配置文件,/mydata/nginx/conf/conf.d/gulimall.conf文件的内容
server {
listen 80;
server_name gulimall.com;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
proxy_set_header Host $host;
proxy_pass http://gulimall;
}
#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;
#}
}
下面是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;
upstream gulimall{
server 192.168.78.1:88;
}
include /etc/nginx/conf.d/*.conf;
}
主机中的hosts文件配置信息是
192.168.78.10 gulimall.com
后台的网关服务的路由配置信息如下
# 放在文件的第一个
- id: product_route
uri: lb://gulimall-product
predicates:
- Path=/api/product/**
filters:
- RewritePath=/api/(?<segment>.*),/${segment}
# 放在文件的最后一个
- id: gulimall_host_route
uri: lb://gulimall-product
predicates:
- Host=gulimall.com,**.gulimall.com
已经整了好久了,希望有好心人能替我解答一下,十分感谢!!!