Using Nginx as a static file server
Summary: nginx installation and tutorial
 nginx  server

Installation

  1. apt install nginx

Config

  1. 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;
    }
  2. make a directory under /etc/nginx/conf.d/ using
    "mkdir /etc/nginx/conf.d/yourconfigname.conf"
  3. 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) img


restart

  1. sudo service nginx restart.
Latest Updated Time:2019-09-19 11:03:04