簡體   English   中英

托管時網站上不加載 Javascript/CSS 文件

[英]Javascript/CSS files don't load on the website while hosting

When I try running my server (with the domain being my IP address), It loads the base index.html but all of the files I reference (other CSS files, javascript files) in my directory aren't loaded.

當我在 Chrome 瀏覽器上運行時,有趣的是,它會讀取我的 index.html 文件目錄中的所有 css/js 文件作為 index.html

在我的默認文件中(在 /etc/nginx/sites-enabled[available]/default 中),我的代碼如下所示:

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  root /usr/share/nginx/html;
  # Add index.php to the list if you are using PHP
  index index.html index.htm index.nginx-debian.html;
  server_name <ip-address-here>;
  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.

    try_files $uri /index.html;

    autoindex on; (I've tried with and w/o this)

    # proxy_pass http://localhost:8080;
    # proxy_http_version 1.1;
    # proxy_set_header Upgrade $http_upgrade;
    # proxy_set_header Connection 'upgrade';
    # proxy_set_header Host $host;
    # proxy_cache_bypass $http_upgrade;
  }
}

之前,我的文件位於名為 /srv/www/xyz.me 的文件夾中。 現在我搬到了/usr/share/nginx/html。 搬家前后我的問題仍然存在。

這是我第一次使用 DigitalOcean。 我已經按照教程來托管我的網站和類似的東西,但我不了解 Nginx 的來龍去脈。

所以我們可以嘗試在配置文件中添加以下內容:

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

我們也可以嘗試將其添加到 /etc/nginx/conf.d/default.conf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM