Welcome! Log In Create A New Profile

Advanced

Make 1 root file accessible, and serve it for all requests

October 20, 2013 11:58PM
I have a version of this working, but I suspect my solution is not the best one.

Please suggest any improvements I can make to my conf file. I am attempting to do the following:

1. If any file is requested from the root, we should always serve "index.html". No other file should be accessible, and requesting anything else should be treated as if you requested "index.html". Currently I'm using rewrite, but a redirect would be okay too, and possibly preferable.

2. Any file under "/css" or "/js" can be requested, and requesting files from those directories that don't exist should return a 404.

Here's my current working conf file:

--- BEGIN CODE ----
server {
listen 80;
server_name www.example.com;
client_max_body_size 50M;

root /var/www/mysite;

location = /index.html {
}

# map everything in base dir to one file
location ~ ^/[^/]*$ {
rewrite ^/[^/]*$ /index.html;
}

location ~ ^/css/ {
}

location ~ ^/js/ {
}
}
--- END CODE ----

Thanks!
Jonah
Subject Author Posted

Make 1 root file accessible, and serve it for all requests

Jonah October 20, 2013 11:58PM

Re: Make 1 root file accessible, and serve it for all requests

B.R. October 21, 2013 01:04AM

Re: Make 1 root file accessible, and serve it for all requests

Jonah October 21, 2013 06:23AM

Re: Make 1 root file accessible, and serve it for all requests

B.R. October 21, 2013 10:24AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 178
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready