Javascript/CSS files don't load on 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.

  • When I run on the Chrome browser, interestingly, it reads all of the css/js files in the directory of my index.html file as that index.html file:

  • In My Default file (in /etc/nginx/sites-enabled[available]/default), my code looks like this:

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;

the rest is just comments

before, my files were in a folder called /srv/www/ Now I moved to /usr/share/nginx/html. Before and after the move my problem still existed.

This is my first time using DigitalOcean. I’ve followed tutorials to host my website and things like that but I don’t understand the ins and outs of nginx.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
September 20, 2019
Accepted Answer

HI @MoGb1,

Is that your whole Nginx configuration?

Additionally, can you try to add the following to the configuration file :

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

You can also try and add it to /etc/nginx/conf.d/default.conf

Kind regards, Kalin

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel