2

I have a some service by running via the docker-compose. as below :

enter image description here

I have my nginx config as below:

# 设置客户端请求体大小限制
client_max_body_size 20M;

# 设置WebDAV方法
dav_methods PUT DELETE;

error_log /var/log/nginx/error.log info;

# 使用 Docker 默认网络的 DNS 解析器
resolver 127.0.0.11 valid=30s;  # 使用 Docker 默认网络的 DNS 解析器

# 主服务器块
server {
    listen 80;
    server_name localhost;

    # 位置块:匹配/v1/system/路径
    location ~ ^/v1/system/(?<service_name>[^/]+)/ {
        set $proxy_pass_url http://$service_name:8080;
        proxy_pass $proxy_pass_url;

        # 代理设置
        include /etc/nginx/conf.d/proxy_settings.conf;
    }

    # 位置块:匹配/v1/hlj/路径
    location ~ ^/v1/hlj/(?<service_name>[^/]+)/ {
        set $proxy_pass_url http://$service_name:8080;
        proxy_pass $proxy_pass_url;

        # 代理设置
        include /etc/nginx/conf.d/proxy_settings.conf;
    }

    # 默认位置块
    location / {
        proxy_pass http://x7:8000;

        # 代理设置
        include /etc/nginx/conf.d/proxy_settings.conf;
    }
      # 定义404页面
    error_page 404 /404.html;
    location = /404.html {
        root /etc/nginx/conf.d/;
        internal;
    }
}

when i visit some path, it sometimes tell me 404 page no found, but I 100% sure I have it on the server. but sometime when I wait for a while it show data with 200 ok. My question is should I using this way to combine my service api as a gateway? or any good way to fix this?

0

Browse other questions tagged or ask your own question.