1、gateway的配置
微服务的基础配置省略
以下是gateway通过nacos的注册中心获取通过服务名端口信息进行的配置的配置文件
- id: xq-media
uri: lb://xq-media
predicates:
- Path=/media/**
- id: xq-common
uri: lb://xq-common
predicates:
- Path=/common/**
- id: xq-content
uri: lb://xq-content
predicates:
- Path=/content/**
- id: xq-message
uri: lb://xq-message
predicates:
- Path=/message/**
- id: xq-search
uri: lb://xq-search
predicates:
- Path=/search/**
- id: xq-system
uri: lb://xq-system
predicates:
- Path=/system/**
2、nginx的配置
打开conf目录的nginx.conf文件
以下为已经配置好的nginx配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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;
}
# 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#服务
server {
listen 9527;
server_name localhost;
location / {
proxy_pass http://localhost:63010;
}
}
}
在server括号中,listen设置为gateway的访问端口,
其中location设置如上,这样可以通过9527端口访问gateway的63010端口进行转发
3、测试
访问端口localhost:9527/media/listByCondition,其中9527后面的路径是接口地址

访问成功,通过nginx转发到gateway,然后再通过gateway解析路径进行二次转发文章来源:https://www.toymoban.com/news/detail-504721.html
一般而言一个nginx配置多个gateway进行转发信息文章来源地址https://www.toymoban.com/news/detail-504721.html
到了这里,关于nginx+gateway集群部署微服务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!