'How to check what is inside nginx root
I am facing a problem where try_files can't recognize static files in my root directory.
I have already checked my root, which is /var/www/public , all the CSS and js files are inside this directory and is not empty. However, nginx fails to recognize and serve my files. It fails to recognize the files, so it passed the request to the .php location block to process uri, which I don't want. I want it to serve the static files directly. Therefore, I would like to check is nginx looking at the same root directory as I think.
Is there any way I can check what is in the directory that nginx check for files? or any way I can figure out what's the problem?
Here is my nginx.conf:
server {
server_name example.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
return 301 https://$host$request_uri;
}
server {
server_name example.com;
listen 443 ssl http2;
access_log /var/log/nginx/access.log vhost;
error_log /var/log/nginx/error_log;
include /etc/nginx/mime.types;
root /var/www/public;
ssl_certificate {ssl_certificate location};
ssl_certificate_key {ssl_certificate_key location};
add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
root /var/www/public;
try_files $uri $uri/ /index.php?$is_args$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass {my_container_name}:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
Please note that I have changed the server name, ssl_certificate info and docker container name for privacy purpose.
Solution 1:[1]
I am answering my own question. The problem was I didn't mount my app volume(the volume that has all code&resources in it) to my nginx container. Problem solved after I mounted the volume.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | work sarah |
