How secure is a vanilla install of nginx with .htaccess authentication?
I have installed nginx on an Arch Linux VPS with Vultr. I intend to use it to serve files to myself and two colleagues. I have setup three accounts for us all with login names and passwords via the .htaccess and .htpasswd files. I will also be adding a certificate with let's encrypt before the server will be used.
The data we will be sharing is commercially sensitive. Is there anything else I need to worry about? Is there anything else I can do to harden the server?
A simple webserver secured by htaccess is not inherit insecure, but there are a lot of steps you can take to improve security further: Like proper authentication via OICD or something similar. Only access to the server via VPN, files encrypted, and so on.
There is lots more that should be considered when hardening the server. You may want to consult a sysadmin if you are doing this commercially. A password is very weak authentication.
I’m not asking from a knowledgeable position, so bear with me if it’s a dumb question: Why don’t people use client certificates for this and restrict access to only clients with the certificate? It seems about as a VPN, and also is revocable, and a time expiry can be put on (I suppose that’s the case with VPNs too). They seem like rather similar solutions but I only see VPNs suggested
The difference is that the client certificates are usually implemented as part of the web server. If there is a issue with either configuration, or bug in the web server, you potentially immediately can bypass the certificate requirement. On the other hand a VPN is often a completely separate piece of software, that is operating at the network layer.
Another thing. If you run a simple port scan against the Internet it is easy to find http/https servers. Some VPN protocols that have been strongly configured will be more or less invisible to any kind of port scans. This eliminates a lot of the scanning and probing get for basically thing that is visible on the Internet.
Not saying client certs don't have their place. Just not sure I would choose them, when I think a VPN provides stronger protection, and is potentially pretty easy to implement for a selfhosted environment.
Just some simple advice, use a vpn if possible to only allow access to resources from it. As soon you’re launching nginx online it will be hammered with brute force and exploit attacks.
nginx doesnt know .htaccess files. You need to configure this in the nginx config. You can use a .htpasswd with some basic auth to get the job done. But I would use something like nextcloud for your usecase.
If you need help with nginx config, just ask 😉
Personally, if correctly configured (and with a strong password), I treat this setup as more secure than anything more complex that I could assemble for myself.
It's very easy to accidentally screw up the configuration. Nginx is generally reverse-proxying some other server; if that server is exposed in any other way than via Nginx, your security is gone.
If you ever transmit the password over http (rather than https) by accident, your security is gone.
If you are somehow treating the three accounts as separate within the underlying application, I wouldn't trust the security of that part; I only use nginx with htpasswd to gate security of single-user apps.
If you're just serving static files, it's harder to mess up and most of these comments don't apply.