I am setting up an nginx webserver for a new website, and I'd like to set the root directory for by webserver to srv
, so I created the /srv
directory and placed all webserver files there, but nginx is not able to find any files within it. I receive an error 404 on every visit. It is able to find the files when root
is set to /var/www/html
though. (or any directory inside /var/www). I am running OpenBSD. Below is my /etc/nginx/nginx.conf
file:
user www;
worker_processes 1;
events {
worker_connections 800;
}
http {
index index.html;
server {
root /srv/foo;
listen 80;
listen [::]:80;
server_name example.com www.example.com;
sendfile on;
tcp_nopush on;
access_log /var/log/nginx/access.log;
location / {
add_header X-uri "$uri" always;
add_header X-docroot "$document_root" always;
add_header X-realroot "$realpath_root" always;
try_files $uri $uri.html $uri/ =404;
}
}
}
All directories and files have read permissions set. Additionally, I have also tried to host the files in a new directory called /usr/srv, but I had the same issue. I am adding headers in the hopes of providing some debug information, but everything looks normal in a curl GET request. I do get an error with the realpath_root header. Below is the log:
2023/06/25 16:30:01 [crit] 14127#0: *32 realpath() "/srv/foo" failed (2: No such file or directory), client: 127.0.0.1, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
Any clue why I am not able to serve from any subdirectory other than /var/www
subdirectories?