How to permanently save a change to nginx.conf (https redirection)

Status
Not open for further replies.

Bee Town

Cadet
Joined
Oct 11, 2013
Messages
3
So I am extraordinarily brave and have a public facing FreeNAS (9.1.1) setup and because of that, I installed a proper SSL certificate for use with HTTPS. Problem is that when configured to use HTTPS, the default Nginix configuration causes it to redirect to the IP address instead of the fully qualified domain name (see: https://bugs.freenas.org/issues/2366).

i.e. if I go to http://nas.beeyourself.com, FreeNAS will redirect you to https://1.2.3.4 which will throw up an error in your web browser since SSL certificates use your domain name.

According to a serverfault thread, the proper Nginx configuration for redirecting http to https (which I've tested on FreeNAS and it totally works) is
Code:
return 301 https://$host$request_uri;
but FreeNAS is configured to set it as
Code:
rewrite ^ https://$server_addr:443$request_uri? permanent;


My question is what is the best way to make that change persist across reboots without waiting for the next iteration of FreeNAS?

My first guess would be to set a cron job or a startup script to make the edit, but I was hoping there was a less messy solution. (Another solution is always typing in https:// when trying to access my server, so it doesn't need to redirect).
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
just mount the freenas drive as rw, make your change and either reboot or set it back to ro
 

Bee Town

Cadet
Joined
Oct 11, 2013
Messages
3
I just tried
1. mount -uw /etc
2. *make change*
3. reboot

and the file was reverted. It seems to me like nginix.conf is a file that is dynamically created on bootup.
 

Dusan

Guru
Joined
Jan 29, 2013
Messages
1,165
It seems to me like nginix.conf is a file that is dynamically created on bootup.
nginx.conf is generated by /etc/rc.d/ix-nginx. However, that script is also "refreshed" on every reboot, so you need to make your change here: /conf/base/etc/rc.d/ix-nginx
You may also want to create a bug report, so that the issue can be fixed directly in FreeNAS: https://bugs.freenas.org/ (and/or prepare a patch and submit a pull request: https://github.com/freenas/freenas/pulls?direction=desc&page=1&sort=created&state=closed)
 

sysfu

Explorer
Joined
Jun 16, 2011
Messages
73
Oops, looks like my bug report might be a dupe of this one filed 7 months ago by Joe G.

It was marked resolved by allowed both http and https without a redirect from the former to the latter. I'm not 100% pleased with this solution, as I want all connections to use https.
 
Status
Not open for further replies.
Top