I have two server blocks and as such
/var/www/mydomain.com/html
/var/www/m.mydomain.com/html
What’s the proper nesting? it should be
/var/www/mydomain.com/images
/var/www/mydomain.com/js
/var/www/mydomain.com/css
or?
in which case how do i get the site to recognize images in those folders since they only seem able to look at the html
folder.
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.
@ariziragoran
What you set as
root
in your server block is where NGINX will look for each request.If your
root
is setup as:and a request on
domain.com
comes through forimages/my_photo.png
, then NGINX will look to/var/www/html/images
formy_photo.png
.You can setup different
root
directories for locations if you want to keep your assets below the web root. For example, if you have this as yourroot
:You could add location blocks, like so, to access the assets below
./html
.I’m using
alias
instead ofroot
so I can specify the full path. You could just as well use something such as:In the above, you’ll notice that all the
root
directives are the same and that’s due to how NGINX handles the request. It appends the request on to theroot
, so if we added the directories to the end of eachroot
(as we did withalias
), the result would be a 404.As an example, let’s say we use this for
/js
instead of the above:When a request comes through for
/js
, NGINX will look to:Which will result in a 404 because
/js/js
doesn’t exist.