Force https on nginx setup

I have setup a MyBB forum using the “Softacoulus” feature. Apparently this setup uses nginx rather than apache. This means that in the folder htdocs there is no .htacess file, but a htacess.txt file. All the examples I found on this forum assumes that there is a .htacess file you can maniphttps://docs.mybb.com/1.8/administration/security/https/ulate to force https. But I found no guide to force https when the setup uses nginx as in my case. I have enabled a Lets Encrypt certificate for my site, and this works as intended when I manually type https://mysite in the browser. But when I just type the domian, the browser assumes http, and no redirect occurs.

I found this on MyBBs own site:

https://docs.mybb.com/1.8/administration/security/https/

But when I do as they suggest when using nginx, namely I edit the htacess.txt file and input what they suggest, still no https redirect.
I would very much appreciate that you (InfinityFree) make a guide for forcing https on both apache and nginx that works on your setup.

Hi and welcome to the forum! If you want MyBB’s rules and your own rules you set before to work, please rename your htaccess.txt file to .htaccess and only use Apache-compatible rules on it. Also, you can’t edit nginx configuration files; on our hosting platform you can use .htaccess files as normal.

4 Likes

Thank you, that worked perfectly :slight_smile:

2 Likes

Just FYI: htaccess files are a feature that’s pretty unique to Apache. NGINX doesn’t have any way to set configuration for individual websites directories through a special file in the directory affected.

Many software developers choose to include their .htaccess file under the name htaccess.txt for ease of use. On Mac and Linux, files starting with a dot are hidden files, so you may not see them in the file list. And Windows just gets confused if a file name doesn’t have the format file-name.type.

Naming the file htaccess.txt avoids any issues there, but you’ll still need to rename them to .htaccess for them to do anything, and even then it only works on Apache servers or servers specifically designed to be compatible with Apache.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.