Config the basic authentication for Web Station of Synology NAS

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

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:

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

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

sudo vi /etc/nginx/sites-enabled/server.webstation-vhost.conf

Add the following

auth_basic "Restricted";
auth_basic_user_file /var/services/web/blog-auth;

After saving, execute the command to verify that the configuration file is correct

sudo nginx -t

If correct, you should see that the system displays the following information

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now, reload the configuration file, execute

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.

本文标题:Config the basic authentication for Web Station of Synology NAS

文章作者:Morning Star

发布时间:2022年01月16日 - 08:01

最后更新:2022年01月18日 - 15:01


许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。