When developing FOTA functions, file servers are occasionally used. This blog briefly introduces how to use nginx to quickly build a local file server under Linux to facilitate testing during development.

Quick Start

Install nginx

1
$ sudo apt-get install nginx

start service nginx

1
$ sudo service nginx restart

More info: Download

Create config file

1
$ sudo gedit /etc/nginx/conf.d/file_server.conf

Modify the config file

1
2
3
4
5
6
7
8
9
10
11
server {
listen 80; # Set listen port
server_name 10.119.119.75; # Set domain name(Local server use ifconfig command query)
charset utf-8; # Avoid Chinese error code
root /home/XXX/share; # Create file path (XXX is the user name of local machine)
location / {
autoindex on; # Index
autoindex_exact_size on; # Show file size
autoindex_localtime on; # Show file time
}
}

More info: nginx config

Make the configuration effective

1
2
$ sudo rm /etc/nginx/sites-enabled/default
$ sudo service nginx reload

Add index.html or source

1
2
3
4
$ pwd
/home/XXX/share
$ ls
img index.html

  Finally, link to the local IP address through the browser to view the file or web page.