前后端微服务联调
前端转发
通过浏览器访问后端服务的时候返回404,有两种情况下会出现
第一种: nginx.conf的配置没有添加 导致出现访问出现404.这种情况的404可以通过nginx的error日志来查看
tail -f /var/log/nginx/error.log
修改nginx.conf
第二种: 后端微服务网关项目的配置没有正确的路由到具体的微服务应用导致后端服务返回404
1.在nginx的err.log看不到404输出 但是在nginx的access.log中出现了404
tail -f /var/log/nginx/access.log
后端gateway的路由配置没有添加
加上网关配置后 发起访问后返回正常
总结:
任何一个请求走的都是两级反向代理
第一级最前端有nginx负责路由转发,第二级由后端网关项目进行路由转发。这两个地方的路由配置都需要同步更新。
网络协议监听
禁用ipv6
sysctl net.ipv6.conf.all.disable_ipv6=1
微服务调用超时
微服务之间通过feign互相调用,跨服务器调用时抛出异常:No route to host
feign调用其他服务也是通过获取eureka注册中心服务,猜测是否服务注册的IP存在问题,查询指定appId的实例
这是由于网络问题 1.有的微服务容器使用了主机网络 2.有的微服务容器使用的不是主机网络
导致微服务之间网络不通造成调用超时
统一所有的微服务网络即可
后端数据库调试
./mysql -S /app/data01/mysql/db/mysql.sock -u root -p
容器环境前后端联调
nginx监听端口但是无法返回html页面
1.查看nginx的error日志 发现是一个权限问题
2.修改文件权限
3.重新启动nginx
浏览器正常打开web服务器上的index.html
nginx返回日志404
后端服务是正常的 但是nginx代理请求后端接口的时候会经常返回404。修改nginx的配置文件
user root; worker_processes 1; error_log /var/log/nginx/error.log; #pid logs/nginx.pid; events { worker_connections 1024; } http { include 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; #client_body_timeout 10; # #client_header_timeout 10; send_timeout 100; server_tokens off; client_max_body_size 50m; map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream gatewayserver { server 192.168.30.123:8008; } upstream websockserver { server 192.168.30.123:8770; } upstream prometheus_servers_http { server 192.168.30.135:3000 max_fails=3 fail_timeout=5s; } sendfile on; #tcp_nopush on; #keepalive_timeout 65; #gzip on; # another virtual host using mix of IP-, name-, and port-based configuration # # HTTPS server # limit_conn_zone $binary_remote_addr zone=one:10m; server { listen 1688; server_name sab; send_timeout 100; client_header_timeout 60000; client_body_timeout 60000; #charset koi8-r; keepalive_timeout 650; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html/; index index.html index.htm; client_max_body_size 100m; #limit_conn one 10; limit_rate 10240k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; //对单个IP的连接数进行了限制 如果前端连接过多超过这个数值的话nginx会直接返回超时 } location /prod-api/ { rewrite ^/prod-api/(.*) /$1 break; root /app/taishi/nginx/html/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /admin-console { proxy_pass http://gatewayserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /schedule { proxy_pass http://gatewayserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /es-service { proxy_pass http://gatewayserver; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_read_timeout 600s; limit_conn one 100; } location /rule { proxy_pass http://gatewayserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /collect { proxy_pass http://gatewayserver; #proxy_read_timeout 300s; #proxy_connect_timeout 300s; #proxy_send_timeout 300s; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /sdc-web { proxy_pass http://gatewayserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /soar-service { proxy_pass http://gatewayserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/soar-service/ { proxy_pass http://gatewayserver/soar-service/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /stage-api/soar-service/ { proxy_pass http://gatewayserver/soar-service/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/schedule/ { proxy_pass http://gatewayserver/schedule/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/admin-console/ { proxy_pass http://gatewayserver/admin-console/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/es-service/ { proxy_pass http://gatewayserver/es-service/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 1000s; limit_conn one 100; } location /prod-api/rule/ { proxy_pass http://gatewayserver/rule/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/collect/ { proxy_pass http://gatewayserver/collect/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /grafana/ { proxy_pass http://prometheus_servers_http; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/sdc-web/ { proxy_pass http://gatewayserver/sdc-web/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /sdc-api-webcenter { proxy_pass http://gatewayserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /prod-api/sdc-api-webcenter/ { proxy_pass http://gatewayserver/sdc-api-webcenter/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } location /stage-api/sdc-api-webcenter/ { proxy_pass http://gatewayserver/sdc-api-webcenter/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; limit_conn one 100; } #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 html; } } # 开启gzip gzip on; # 启用gzip压缩的最小文件,小于设置值的文件将不会压缩 gzip_min_length 1k; # gzip 压缩级别,1-9,数字越大压缩的越好,也越占用CPU时间,后面会有详细说明 gzip_comp_level 2; # 进行压缩的文件类型。javascript有多种形式,后面的图片压缩不需要的可以自行删除 gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 是否在http header中添加Vary: Accept-Encoding,建议开启 gzip_vary on; # 设置压缩所需要的缓冲区大小 gzip_buffers 4 16k; proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=10g; }
本文来自博客园,作者:不懂123,转载请注明原文链接:https://www.cnblogs.com/yxh168/p/14482593.html