node.js - 无法使用 NGINX 和 Digital Ocean 服务静态文件
问题描述
/etc/nginx/sites-available/默认配置。您好,我正在使用为我的应用程序设置的 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;
}
推荐阅读
- c# - 如何使用 A* 管理“无路径”场景
- python - 无法让 Discord 机器人上线
- python - 我正在尝试找到一种使用 Python 邮寄文件内容的方法
- javascript - 使用 Jasmine 进行测试,结果失败:未捕获(承诺中):TypeError:无法读取未定义的属性“firstName”
- java - 如何测量我的 Java + MongoDB 应用程序操作的毫秒/纳秒性能?
- c++ - std::is_invocable 在模板类型上的意外结果
- django - 如何在模型序列化器中将嵌套字段设为只读?
- python - 在 python 中,我们如何使用证书、订阅密钥连接到 API?
- python - 将不同的 sys.argv 传递给同一个 docker run 端口
- web-crawler - 使用 Stormcrawler 爬取特定子目录