I'm having a lot of trouble setting up this alias inside nginx to display my website correctly.
The website I'm concerned with should be accessible from mywebsite.com/mr
and is different from the site located at mywebsite.com/
. The website is located at /fullpath
(shortened for simplicity) The site needs to serve three kinds of content:
/fullpath/index.html
..html
extension in the browser)./fullpath
and subdirectories.I've tried changing around the order of matches in the try_files
and found situations where they all worked, just not at the same time:
location /mr { default_type "text/html"; alias /fullpath; # with this one 1 and 3 work # try_files $uri/index.html $uri.html $uri; # with this one 2 and 3 work # try_files $uri $uri.html $uri/index.html; # with this one 1 and 2 work try_files $uri.html $uri/index.html $uri; }
When one doesn't work it 404's. Does anybody know how I can serve all kinds of files correctly?
To serve static files with nginx, you should configure the path of your application's root directory and reference the HTML entry point as the index file. In this example, the root directory for the snake deployment is /home/futurestudio/apps/snake which contains all the files.
By default Nginx Web server default location is at /usr/share/nginx/html which is located on the default file system of the Linux.
Configure NGINX and NGINX Plus to serve static content, with type-specific root directories, checks for file existence, and performance optimizations.
Apparently alias and try_files don't work together. However, I don't think you need to use alias.
location /mr { default_type "text/html"; try_files /fullpath/$uri /fullpath/$uri.html /fullpath/$uri/index.html /fullpath/index.html; }
Which would try:
I think the root directive does work with try files but am unable to test.
server{ location /mr { root /home/mysite/fullpath; default_type "text/html"; try_files $uri $uri.html $uri/index.html index.html; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With