How to Force a Domain to Use HTTPS on a Directadmin Server with nginx

By | March 20, 2018

If you need to have only https access to a domain, you’ll have to set up proper redirection. Since .htaccess files are not working in case you have selected nginx as your web server, you’ll have to adjust your configuration files. Let me show you how to do this in Directadmin, without even touching any files. If you need a solution for Apache – you’ll just need to add a simple .htaccess file as user – check here.

First open Directadmin as admin, choose Admin Level and scroll down for Extra Features -> Custom HTTPD Configurations

directadmin custom httpd

If you need the direct address, here it is:

https://yourdomain.com:2222/CMD_CUSTOM_HTTPD

Then search for your domain name and click it.

Click Additional Custom Tokens

Then choose CUSTOM4

And insert the following code into this section:

|*if SSL_TEMPLATE="0"|
       return 301 https://$host$request_uri;
|*endif|

Click Save. Now it’s time to restart nginx to enable these changes.

Go to Service Monitor:

https://yourdomain.com:2222/CMD_SHOW_SERVICES

Click Restart for nginx.

That’s it! You should now have your site redirected to HTTPS, of course, if you have set an SSL access as user.

Leave a Reply