Using synology NAS’s Web Station suite, we can quickly and easily configure a Web site in the NAS, but if we want to configure a simple user authentication feature for that site, Web Station doesn’t provide a ready-made setup method. This article demonstrates how to resolve this issue - configuring simple user authentication for static Web sites in synology nas.
Because the Web Station of the Synology NAS uses Nginx as the web server, we can use Nginx’s authentication feature to set it up.
First, log in to the NAS using ssh. Go to the settings directory for nginx
1 | cd /etc/nginx |
Make a password file
Make a password file with the htpasswd password, because nginx is run with the http user in synology nas, so you need to establish the password file where the http user can access it. In this example, we build the file in the /var/services/web directory.
Assuming that a user named guest is authorized to access the site, execute:
1 | sudo htpasswd -c /var/services/web/blog-auth guest |
Enter the password set for the guest user when prompted. After the file is created, remember to change the owner of the file to http, execute
1 | sudo chown http:http /var/services/web/blog-auth |
Modify the Nginx configuration file
The configuration file for each vhost configured in Web Station is /etc/nginx/sites-enabled/server.webstation-vhost.conf, so we edit the file
1 | sudo vi /etc/nginx/sites-enabled/server.webstation-vhost.conf |
Add the following
1 | auth_basic "Restricted"; |
After saving, execute the command to verify that the configuration file is correct
1 | sudo nginx -t |
If correct, you should see that the system displays the following information
1 | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok |
Now, reload the configuration file, execute
1 | sudo nginx -s reload |
Now if you visit a website on the NAS, a prompt box will appear, and you can only continue browsing the website if you enter the correct username and password.