Editing Nginx configuration

Status
Not open for further replies.

cwilliams

Dabbler
Joined
Aug 19, 2013
Messages
10
Hi, I have a need to edit the nginx configuration. I wish to use my freenas box as a http proxy to cache steam traffic (its in an office serving approx 200 people). The problem with this is that everytime the service is restarted (I'm using ix-nginx restart). The nginx configuration is overwritten. I've had a read through ix-nginx and am wondering if I make the changes I require to the template it automatically creates for nginx.conf whether this is going to be the simplest option and whether there are any implications in doing this?

Thanks
 

Whattteva

Wizard
Joined
Mar 5, 2013
Messages
1,824
If you want to do anything custom, do it in a jail, not to the FreeNAS itself.
Anything custom you do through FreeNAS that's not through the webadmin will generally not survive reboots because it's all configured through a database.
Make a separate jail and install nginx there and you can do whatever you wish there. FreeNAS is designed this way to keep the base install pristine.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
I agree with Whattteva. You aren't supposed to be playing with nginx from the FreeNAS install. You should instead go through a jail and use that to accomplish your task.

As you are seeing, many files are regenerated on bootup based on your FreeNAS configuration from the WebGUI. In your case, FreeNAS was never designed to do what you want(its a file server... right?) but the jail was created for any "extracurricular" activities you may want to do with your server.
 

cwilliams

Dabbler
Joined
Aug 19, 2013
Messages
10
I will give that a go, I guess if it fails, its an excuse to properly learn how to use freebsd instead :)

Thanks
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
Have a problem, that I moved the FreeNAS box to another net, and it got a different DHCP address.
nginx wont start since it is configured to listen to the "old" ip address.

If I look at the /etc/local/nginx/nginx.conf

it contains the line
10.175.196.24:80 listen

but the ip address is now: 10.1756.196.245

How fix this?
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
Sorry,

My problem is that I need to change the nginx configuration,
and since it does not start I have to do it from a shell.

In other Forums i have participated in, they prefer to keep threads
going, instead of starting new threads, so I thought it was appropriate
to continue this thread. I have no problem starting a new one.

Meanwhile I found a workaround.
I edited /etc/local/nginx/nginx.conf (which normally is write protected)
and started nginx manually.
From a web browser I then changed the web server from 0.0.0.0
(which results in FreeNAS trying to read from the previous DHCP lease)
to 10.175.196.245, which is my current lease, and nginx now uses this
after a reboot.

Obviously I have to repeat this the next time I move the NAS.

Feels like this is a bug in FreeNAS 8.3.1 p2

Dont know if this can be repeated if the configuration is set to a fixed
address so I changed the configuration back to 0.0.0.0.
Have TWO 0.0.0.0. Options which is strange....
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
You do realize that what you did is not recommended at all. Mostly because you've done a whole bunch of things that may have consequences you aren't aware of since you're deviating from FreeNAS original design. In particular, because you can change the IP address from the GUI where it is changed in the FreeNAS configuration as well as your slight "hackjob". If you had gone to System->Settings->General you can choose the IP address from a dropdown box.

Not sure why you chose to take a more complex alternative. Quite often when people do things that don't appear to have serious consequences they regret it later. Just a few days ago I had to explain to someone that what they had done was against the recommendations of the manual. Not surprisingly, his problems were directly a result of him choosing to do things from the CLI instead of the manual.

Now I can't predict any possible consequences for what you did since everyone else uses the GUI setting, but at the minimum your changes will be lost the next time you upgrade to boot.
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
Nginx is not running so I do not have the option to configure using a web browser.

This is not the way I want to do things, but if the FreeNAS user interface
is unavailable because nginx tries to listen to the wrong interface, and aborts
during boot, what are the option?

I understood that changes in the file was lost after reboot, but after the change to the conf file,
I started nginx and changed stuff in the browser, and those changes appears permanent.

The core of the problem is that FreeNAS seems to assume it will always get the same IP address
from the DHCP server.

Still wondering why I have two 0.0.0.0 to choose from in the dropdown list.
Are they really equivalent, or are they somehow related to DHCP leases,
and you have to choose the "right" one?
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Nginx is not running so I do not have the option to configure using a web browser.

This is not the way I want to do things, but if the FreeNAS user interface
is unavailable because nginx tries to listen to the wrong interface, and aborts
during boot, what are the option?
And you should be investigating why that isn't working right and not trying to circumvent things that you think are wrong. Something else is wrong if nginx isn't doing its job, and that should be where you should be troubleshooting. Maybe try reinstalling FreeNAS to a different USB stick in case its corrupted.

I understood that changes in the file was lost after reboot, but after the change to the conf file,
I started nginx and changed stuff in the browser, and those changes appears permanent.

The core of the problem is that FreeNAS seems to assume it will always get the same IP address from the DHCP server.

I'm not too concerned about things being lost after reboot. I'm more concerned with months later when you have a problem and because you did what you did you have a config file that is corrupted because of confusion and you are forced to reset your FreeNAS installation and start over. For many people that's far from trivial to deal with.

As for it getting the same DHCP server, if you aren't happy with the IP then go into you DHCP server and assign it another IP address or manually force an IP from the FreeNAS GUI. Notice no CLI commands needed. ;)

Still wondering why I have two 0.0.0.0 to choose from in the dropdown list.
Are they really equivalent, or are they somehow related to DHCP leases,
and you have to choose the "right" one?

If you were using the manual you'd know what the 0.0.0.0 means as its clearly described in the section of the manual for the General Tab of the GUI(section 4.7).

Please don't take this as an insult, but you are trying to jury-rig FreeNAS to work in a situation where you should be asking what is actually wrong. It seems like you are very confused on how networks actually work and are too busy trying to mess with FreeNAS than solve your network configuration issues. I'd slow down and consult a friend or co-worker to help you with this as you seem very confused. The manual really is well written and answers many questions for newbies.

Just trying to save you from a lot of potential headaches later.
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
And you should be investigating why that isn't working right and not trying to circumvent things that you think are wrong. Something else is wrong if nginx isn't doing its job, and that should be where you should be troubleshooting. Maybe try reinstalling FreeNAS to a different USB stick in case its corrupted.



I'm not too concerned about things being lost after reboot. I'm more concerned with months later when you have a problem and because you did what you did you have a config file that is corrupted because of confusion and you are forced to reset your FreeNAS installation and start over. For many people that's far from trivial to deal with.

As for it getting the same DHCP server, if you aren't happy with the IP then go into you DHCP server and assign it another IP address or manually force an IP from the FreeNAS GUI. Notice no CLI commands needed. ;)



If you were using the manual you'd know what the 0.0.0.0 means as its clearly described in the section of the manual for the General Tab of the GUI(section 4.7).

Please don't take this as an insult, but you are trying to jury-rig FreeNAS to work in a situation where you should be asking what is actually wrong. It seems like you are very confused on how networks actually work and are too busy trying to mess with FreeNAS than solve your network configuration issues. I'd slow down and consult a friend or co-worker to help you with this as you seem very confused. The manual really is well written and answers many questions for newbies.

Just trying to save you from a lot of potential headaches later.

I know why it is not running. It is because it gets confused if the DHCP address is changes.

Location 1: DHCP provides 10.175.196.24
Location 2: DHCP provides 10.175.196.245

When the FreeNAS server is in location it tries to listen to the DHCP lease of location 1.
That is the core of the problem, and this I consider a bug.
If you move the FreeNAS to another location this bug results in the user interface
not beeing availalbe, and any suggestion to reconfigure the NAS using a web browser
is impossible.


- As for changing DHCP leases, In theory it would work, but not so easy for me...

I am using the same network range in both locations, because I have a lot of embedded H/W using fixed addresses.
One of the routers restricts the range of DHCP leases to a defined subrange
incompatible with the other setup, so they will not get the same address.

The other router does not allow you to *change* the lease. You can only define the lease
before you connect the first time. I consider this a bug in the router.
- Not that it is an el cheapo router. Was over $200 from Linksys.

(Maybe not connecting for the lease time, will get you out of the mess, but that is not feasible,
resetting the router and set it up from scratch is also a pain).

Anyway, I do not consider this to be the core of the problem. It is another workaround.

The real problem is that FreeNAS remembers DHCP leases between reboots,
and that is where I think we should focus the discussion on this point.

What in FreeNAS is generating /etc/local/nginx/nginx.conf at boot and why
does that look at the prveious boot, instead of the current DHCP lease?

Once that problem is fixed, then I do not have any problems.

---------------------------
BTW; I have read the manual and it explains that 0.0.0.0 is "any address", but it does not explain why I have two "0.0.0.0"

----
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
As for your IPs, a DHCP server should own a particular range of IPs within its subnet. It sounds like(if I'm understanding you), that you've effectively broken your network because of this. I'm thinking that you're going to find out a little later that you actually have alot more uphill battles later, many of which I don't think you can fix because your network topology is not correct.

The real problem is that FreeNAS remembers DHCP leases between reboots,
and that is where I think we should focus the discussion on this point.

FreeNAS does NOT remember DHCP leases between reboots. In fact, if you watch the bootup sequence you'll see something like:

em0 is up
Sending DHCP request
DHCP address assigned... (bunch of info on your network)
em0 IP is X.X.X.X

I really don't know how to help you. If your network topology is as broken as it sounds like it is, you've got a lot of problems coming up you probably aren't even ready to deal with. Some of which you might not be able to fix no matter how hard you try.

FreeNAS doesn't take well to broken network topologies, and if you search the forums you'll see us commonly use the phrase "you failed networking-101" because the basic concepts of how the network functions is broken. Windows is slightly more forgiving, and many people that have had broken network cofigurations for years come to FreeNAS and think FreeNAS is broken. The reality is that they don't know what they are doing and FreeNAS is simply making that obvious when it doesn't work as they expect.

I'm sorry, I've got no further advice to provide you. Good luck in your endeavors. I'm expecting you're going to have a lot more questions as you begin setting up your network and I think you're going to hear "fix your network, you can't fix it by reconfiguring FreeNAS" for at least a few of them. But this thing you are doing with editing configuration files manually, it's going to backfire at some point. And you're going to be a little more than just inconvenienced when it bites you. :(
 

Dusan

Guru
Joined
Jan 29, 2013
Messages
1,165
The real problem is that FreeNAS remembers DHCP leases between reboots,
and that is where I think we should focus the discussion on this point.
Something must be broken in your installation as FreeNAS does not normally behave like this. I can change the IP of my box between reboots and the Web GUI is always available at the new IP.
What in FreeNAS is generating /etc/local/nginx/nginx.conf at boot and why
does that look at the prveious boot, instead of the current DHCP lease?
The config is generated by /etc/rc.d/ix-nginx, you can run service ix-nginx quietstart to trigger regeneration of nginx.conf.
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
As for your IPs, a DHCP server should own a particular range of IPs within its subnet. It sounds like(if I'm understanding you), that you've effectively broken your network because of this. I'm thinking that you're going to find out a little later that you actually have alot more uphill battles later, many of which I don't think you can fix because your network topology is not correct.

The DHCP servers own their own address ranges. but the ranges are different on the two networks due to limitations of the routers..
The static IP addresses are all outside the ranges.
I dont think the network is broken as such.
Since I have been running my own Unix/Solaris/Linux machines since 1984, I think I do understand the networking aspect.

FreeNAS does NOT remember DHCP leases between reboots. In fact, if you watch the bootup sequence you'll see something like:

em0 is up
Sending DHCP request
DHCP address assigned... (bunch of info on your network)
em0 IP is X.X.X.X

As I said,the FreeNAS box will get their address from the DHCP server in a proper manner.
The reason I claim that it "remebers", is that nginx.conf is not regenerated to use the DHCP lease,
it uses the lease from the other network.

I really don't know how to help you. If your network topology is as broken as it sounds like it is, you've got a lot of problems coming up you probably aren't even ready to deal with. Some of which you might not be able to fix no matter how hard you try.

FreeNAS doesn't take well to broken network topologies, and if you search the forums you'll see us commonly use the phrase "you failed networking-101" because the basic concepts of how the network functions is broken. Windows is slightly more forgiving, and many people that have had broken network cofigurations for years come to FreeNAS and think FreeNAS is broken. The reality is that they don't know what they are doing and FreeNAS is simply making that obvious when it doesn't work as they expect.

I'm sorry, I've got no further advice to provide you. Good luck in your endeavors. I'm expecting you're going to have a lot more questions as you begin setting up your network and I think you're going to hear "fix your network, you can't fix it by reconfiguring FreeNAS" for at least a few of them. But this thing you are doing with editing configuration files manually, it's going to backfire at some point. And you're going to be a little more than just inconvenienced when it bites you. :(
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
Something must be broken in your installation as FreeNAS does not normally behave like this. I can change the IP of my box between reboots and the Web GUI is always available at the new IP.

The config is generated by /etc/rc.d/ix-nginx, you can run service ix-nginx quietstart to trigger regeneration of nginx.conf.

Thanks, this is useful information.

Now I think I know what is going on.

I think that I must have set the web server to listen to 10.175.196.24 in the GUI at the other location.
I remembed I had some problems after power-loss and was experimenting to get it running properly.
The real problem at that point, I discovered that Internet Explorer (at least the version I used)
did not work properly with FreeNAS, but Firefox did.

When I return to this location, it is still "forced" to 10.175.196.24,
and since it gets 10.175.196.245 from the DHCP server it will fail.
This is all very natural. It does what it is told.

It is not the complete story, because I think there must be a difference
between when you power down normally, and when there is sudden power loss.

nginx was not accessible when I returned from the second location, but
after a power loss, It was available in the next boot, until I rebooted.
Then it was lost again...
 

Whattteva

Wizard
Joined
Mar 5, 2013
Messages
1,824
It is not the complete story, because I think there must be a difference
between when you power down normally, and when there is sudden power loss.

nginx was not accessible when I returned from the second location, but
after a power loss, It was available in the next boot, until I rebooted.
Then it was lost again...
This is a bit off-topic, but... I would invest in a UPS if I were you... at least if you value your data at all.
 

ulf

Dabbler
Joined
Apr 23, 2013
Messages
33
Almost all my data is MPEG4 movies recorded from TV to DVDs so I have the DVDs to start with, then I plan to rsync the stuff to another machine which has an Ultrium 4 tape streamer.
This will be up and running soon.
On top of that I share the movies with my brother so it is stored in another location.
Then in worst case, I can always hope for a new broadcast.
I think that I can live without the UPS.
 

Whattteva

Wizard
Joined
Mar 5, 2013
Messages
1,824
Fair enough. No need for it if you don't really care about losing it in the first place.
I just always assume the worst because I think there are generally more people that care about losing the data.
 
Status
Not open for further replies.
Top