Issue
I have a Magento application and I try to run it on a CentOS 7 server. I am able to access the application in the browser. However, files like css
and js
can't be found because the root location of the application on the server is added to the url.
So for example a file is located at: https://www.example.com/css/my_file.css
But the browsers is requesting it from: https://www.example.com/usr/share/nginx/application_name/css/my_file.css
How can I get the correct path?
I have Nginx version 1.16.1 installed. Nginx is listening on port 8080 because it is behind Varnish which listens on port 80. This is the vhost:
server {
listen 8080 default_server;
server_name www.example.com;
root /usr/share/nginx/application_name;
index index.php;
location ^~ /app/ { return 403; }
location ^~ /db/ { return 403; }
location ^~ /dev/ { return 403; }
location ^~ /downloader/pearlib { return 403; }
location ^~ /downloader/template { return 403; }
location ^~ /downloader/Maged { return 403; }
location ~* ^/errors/.+\.xml { return 403; }
location ^~ /includes/ { return 403; }
location ^~ /lib/ { return 403; }
location ^~ /media/downloadable/ { return 403; }
location ^~ /shell/ { return 403; }
location ^~ /var/ { return 403; }
location ^~ /varnish/ { return 403; }
location ^~ /vendor/ { return 403; }
location ~ .phtml$ { return 403; }
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE base;
fastcgi_param MAGE_RUN_TYPE website;
include fastcgi_params;
fastcgi_read_timeout 90;
}
}
Solution
Turns out the media
folder of Magento was not writable for nginx and therefore the full path is used to retrieve the files.
Setting the correct permissions made it work.
Answered By - Pascal Answer Checked By - Marilyn (WPSolving Volunteer)