Nginx: Complete server path being inserted before images, CSS, JS...

I’m running Nginx on CentOS. My primary site is running as it should be on the site - no issues there. However, I’ve created a demo site for a client and I am running it in a sub-directory under and see the PHP/HTML no problem but anything related to images, CSS or JS is having the full root server path inserted before it (e.g. I’m certain this is related to Nginx configuration file but I’ve modified it several times and restarted with no luck. Has anyone else run into this issue?

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

<blockquote>I think I see the problem… Nginx doesn’t recognize .htaccess files.</blockquote> <br>Nope, see <a href=“”></a>. <br> <br>Have you managed to get it working?

I think I see the problem… Nginx doesn’t recognize .htaccess files.

I thought the same about the hardcoding but it is only happening on my staging server here at Digital Ocean and not on the production environment. Here is my default.conf: <br> <br># <br># The default server <br># <br>server { <br> listen 80; <br> server_name; <br> <br> <br> location / { <br> root /usr/share/nginx/html; <br> index index.php index.html index.htm; <br> } <br> <br> error_page 404 /404.html; <br> location = /404.html { <br> root /usr/share/nginx/html; <br> } <br> <br> error_page 500 502 503 504 /50x.html; <br> location = /50x.html { <br> root /usr/share/nginx/html; <br> } <br> <br> # pass the PHP scripts to FastCGI server listening on <br> # <br> location ~ .php$ { <br> root /usr/share/nginx/html; <br> fastcgi_pass; <br> fastcgi_index index.php; <br> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; <br> include fastcgi_params; <br> } <br>} <br> <br>_______________ <br> <br>I assumed it was the “root /usr/share/nginx/html” towards the end but after commenting it out, it still does the same thing. Here is my virtual.conf (ip has been changed for anonymity): <br> <br>_______________ <br># <br># A virtual host using mix of IP-, name-, and port-based configuration <br># <br> <br>server { <br> # listen 80; <br> listen; <br> server_name; <br> <br> location / { <br> root /usr/share/nginx/html/; <br> index index.php index.html index.htm; <br> <br> <br>#location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { <br># expires 365d; <br> <br>#} <br> <br>location ~ .php$ { <br>fastcgi_pass; <br>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; <br>include fastcgi_params; <br>} <br> <br> } <br>} <br>