Using Nginx as a static file server
Installation
- apt install nginx
Config
- sudo nano /etc/nginx/nginx.conf, in the file, add include /etc/nginx/conf.d/*.conf; in http. If the config file already have this line, ignore this step.
http{ include /etc/nginx/conf.d/*.conf; }
make a directory under /etc/nginx/conf.d/ using
"mkdir /etc/nginx/conf.d/yourconfigname.conf"edit the config file you just made.
server { listen 80; server_name xxx.com; location / { root /home/filestation; autoindex on; } }
listen: the port of nginx server
server_name: your domain, for example: myserver.com
location: the http entry point
root: the real file route.
For example: if you set location / and root /home/filestation, you can access your /home/filestation/myfile.txt at myserver.com/myfile.txt
if you set location /abc and root /home/filestation, you can access your /home/filestation/abc/myfile.txt at myserver.com/abc/myfile.txt
autoindex: if you can access to the directory. (on/off)
restart
- sudo service nginx restart.