无法使用NGINX和Digital Ocean服务静态文件

问题描述

/ etc / nginx / sites-available / default conf。 您好,我正在使用DigialOcean NodeJS为我的应用程序设置的一键式应用程序。 NGINX正在提供我的HTML文件,但没有提供我的CSS或Java文件。我试图为公用文件夹添加位置块,这是我的样式表,图像和Java文件所在的位置。我不太了解NGINX,因此不胜感激。

      ##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases,administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications,such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name,such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
server {
      listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /Portfolio;

        # Add index.php to the list if you are using PHP
        index index.html  index.htm index.nginx-debian.html;

        server_name 157.230.203.182;

               location ^~ /assets/ {
                gzip_static on;
                expires 12h;
                add_header Cache-Control public;
  }

        location / {
         proxy_http_version 1.1;
                proxy_cache_bypass $http_upgrade;

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;

                proxy_pass  http://localhost:8080;
        }
}

解决方法

我必须添加

location ~* \.(css|gif|html|ico|jepg|jpg|mp4||js|jsx|pdf|php|png|scss|svg|txt|zip) {
             add_header        Cache-Control public;
             add_header        Cache-Control must-revalidate;
          }
现在可以使用,但是我必须添加上面的代码 不知道为什么这段代码会说实话。如果有人可以解释的话会有所帮助。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...