Report this

What is the reason for this report?

Hi, Nginx is returning 404 because it could not find my .js and .css files

Posted on January 14, 2019

i logged into the container and i see those files inside static directory

default.conf

server { listen 8080; server_name localhost;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    try_files $uri $uri/ /index.html;
    index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

location ~ (js|css|img) {
  try_files $uri =404;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}

dockerfile

RUN rm -rf /etc/nginx/conf.d/default.conf
COPY ./default.conf /etc/nginx/conf.d/
COPY ./build/ /usr/share/nginx/html
RUN touch /var/run/nginx.pid && \
  chown -R 1001:1001 /var/run/nginx.pid && \
  chown -R 1001:1001 /var/cache/nginx && \
  chmod -R 777 /var/log/nginx /var/cache/nginx/ && \
  chmod -R 777 /etc/nginx/* && \

  


EXPOSE 8080


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!

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.

@prudhvi

You need to put default.conf in /etc/nginx/sites-available and create a symlink for it from /etc/nginx/sites-enabled change the second line from Dockerfile as follows:

COPY ./default.conf /etc/nginx/sites-available
RUN ln -s /etc/nginx/sites-available/default.con /etc/nginx/sites-enabled

Then try again.

hope this helps.

i am using nginx :alphine as the base image so nginx should be there by default, i am gonna check on it and revert back.

@Mohsen47 i did as you suggested but same result and i don’t see sites-available and sites-enabled directories in /etc/nginx/ when i logged into the container

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.