小编ran*_*ran的帖子

除非在 url 中指定 .json,否则 nginx 不会提供 json 文件

我有以下 nginx.conf 文件:

server {
    listen 8080;
    server_name dummy_server;

    root /usr/share/nginx/html;

    location / {
      if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain; charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
      }

      default_type 'application/json';
      add_header 'Access-Control-Allow-Origin' '*' always;
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
      add_header 'Content-Type' 'application/json';
      if ($request_uri ~* "([^/]*$)" ) {
        set  $last_path_component  $1;
      }

      try_files $last_path_component.json $last_path_component.json =404;
    }
  }
Run Code Online (Sandbox Code Playgroud)

我想healthcheck.jsonlocalhost:8080/v1/healthcheck被要求时提供服务。但是,如果我没有明确点击 ,nginx …

nginx docker-compose

5
推荐指数
1
解决办法
4811
查看次数

标签 统计

docker-compose ×1

nginx ×1