首页 > 解决方案 > nginx服务404而不传递给代理

问题描述

我有简单的设置来部署 angular、springboot、mysql 堆栈。我通过 nginx 提供这个服务,使用这个配置

server {
    listen 8081;
    server_name _;
    root   /usr/share/nginx/html;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_min_length 32;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript font/opentype image/svg+xml image/x-icon application/javascript application/x-font-ttf application/x-font-otf application/font-woff application/font-woff2 application/vnd.ms-fontobject application/octet-stream;

    error_log stderr info;
    access_log /dev/stdout main;
       
    location /api {
             proxy_pass http://backend:8080/;
        }

    location /app {
        root   /usr/share/nginx/html;
        try_files $uri$args $uri$args/ $uri/ /index.html;
        #index  index.html index.htm;
    }

    
}

应用程序服务良好,但是当我尝试获取 localhost:8081/api 它以 404 结尾,并且在日志中我看到 nginx 以 404 结尾,而没有传递到后端。难道我做错了什么?

标签: nginx

解决方案


推荐阅读