Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js SwiggerUI-(Express)静态资源上使用404的NGINX响应_Node.js_Express_Nginx_Swagger - Fatal编程技术网

Node.js SwiggerUI-(Express)静态资源上使用404的NGINX响应

Node.js SwiggerUI-(Express)静态资源上使用404的NGINX响应,node.js,express,nginx,swagger,Node.js,Express,Nginx,Swagger,swaggerUI在我的本地主机上工作,但当我尝试将其与nginx集成时,它就不起作用了 当您试图获取静态招摇过市文件时,服务器找不到它们。可能是反向代理不起作用。有什么想法吗 以下是配置文件和日志文件: nginx*的error.log 2020/01/29 13:47:54 [error] 933#933: *2432 open() "/usr/share/nginx/html/documentation/swagger-ui.css" failed (2: No such file or

swaggerUI在我的本地主机上工作,但当我尝试将其与nginx集成时,它就不起作用了

当您试图获取静态招摇过市文件时,服务器找不到它们。可能是反向代理不起作用。有什么想法吗

以下是配置文件和日志文件:

nginx*的error.log

2020/01/29 13:47:54 [error] 933#933: *2432 open() "/usr/share/nginx/html/documentation/swagger-ui.css" failed (2: No such file or directory), client: 190.190.190.28, server: mywebsite.com.com, request: "GET /documentation/swagger-ui.css HTTP/2.0", host: "mywebsite.com", referrer: "https://mywebsite.com/documentation/"
2020/01/29 13:47:54 [error] 933#933: *2432 open() "/usr/share/nginx/html/documentation/swagger-ui-bundle.js" failed (2: No such file or directory), client: 190.190.190.28, server: mywebsite.com, request: "GET /documentation/swagger-ui-bundle.js HTTP/2.0", host: "mywebsite.com", referrer: mywebsite.com/documentation/"
2020/01/29 13:47:54 [error] 933#933: *2432 open() "/usr/share/nginx/html/documentation/swagger-ui-standalone-preset.js" failed (2: No such file or directory), client: 190.190.190.28, server: mywebsite.com, request: "GET /documentation/swagger-ui-standalone-preset.js HTTP/2.0", host: "mywebsite.com", referrer: "https://mywebsite.com/documentation/"
site.conf[nginx]

# Expires map
map $sent_http_content_type $expires {
    default                    off;
    text/css                   1y;
    application/javascript     1y;
    ~image/                    1M;
}

server {
    server_name mywebsite.com;

    expires $expires;

    index index.html;

    include mime.types;
    default_type application/octet-stream;

    sendfile on;

    location ~ \.css
    {
      add_header Content-Type text/css;
    }

    location ~ \.js
    {
      add_header Content-Type application/javascript;
    }

    location /
    {
      expires -1;
      add_header Pragma "no-cache";
      add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
      #root /var/www;
      try_files $uri $uri/;
      return 301 https://mywebsite.com/documentation;
    }

    location ~* \.(?:manifest|appcache|html?|xml|json)$
    {
      expires -1;
    }

    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$
    {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
    }

    location ~* \.(?:css|js)$
    {
      expires 1d;
      access_log off;
      add_header Cache-Control "public";
    }

    location /api/ {
      proxy_pass http://127.0.0.1:4000/api/;
      proxy_http_version 1.1; # this is essential for chunked responses to work
      proxy_buffering    off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      # set client body size to 200M #
      client_max_body_size 200M;
    }


    location /documentation/ {
      proxy_pass http://127.0.0.1:4000/documentation/;
      proxy_http_version 1.1; # this is essential for chunked responses to work
      proxy_buffering    off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      client_max_body_size 200M;
    }

   .... ####  Certbot conf #### ....

}
swaggerDoc.js(express)


您缺少位置块的
。它会导致nginx在为静态文件提供服务时失败。如果静态资产存储在同一路径下,则可以按如下方式移动服务器块中的
根目录

server {
    server_name mywebsite.com;

    expires $expires;

    index index.html;

    include mime.types;
    default_type application/octet-stream;

    root /api/static;    # change this to your path

    # the rest of your configuration
}

问题是这些文件是由swagger动态生成的,它们不在特定的目录中:(@otta为了测试起见,你能试着在你的配置中注释这个块吗?`location~*.(?:jpg | jpeg | gif | png | ico | cur | gz | svg | svg | mp4 | ogg | ogv | webm | htc)${…}`此外,文件是动态生成的,但路径不变;nginx尝试从默认文件夹
/usr/share/nginx/html/
获取资产,这是您文档的基本路径吗?您甚至可以在调用
swagger codegen
命令时使用
-output
标志指定swagger输出路径。I对您所说的行进行了评论,但仍然不起作用。我使用的是文档。静态文件位于node_modules/swagger ui dist文件夹中,我认为将根目录指向该文件夹没有意义…swagger ui express库不会生成静态文档:(
server {
    server_name mywebsite.com;

    expires $expires;

    index index.html;

    include mime.types;
    default_type application/octet-stream;

    root /api/static;    # change this to your path

    # the rest of your configuration
}