Report this

What is the reason for this report?

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

Posted on December 27, 2013

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 mydomain.com/sites/clientsite/ 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. mydomain.com/usr/share/nginx/html/sites/clientsite/bg.jpg). 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?



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.

Please pastebin your nginx config, is your app generating the asset links or are they hardcoded in?

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 mydomain.com; <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 127.0.0.1:9000 <br> # <br> location ~ .php$ { <br> root /usr/share/nginx/html; <br> fastcgi_pass 127.0.0.1:9000; <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 12.34.55.78:80; <br> server_name mydomain.com www.mydomain.com; <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 127.0.0.1:9000; <br>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; <br>include fastcgi_params; <br>} <br> <br> } <br>} <br>

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.