Nginx's config file nginx.conf is loaded statically or dynamically? - nginx

Will nginx loads its nginx.conf file statically? Is there a way to change the content of file later and can it be dynamically updated? If yes, how it can be done?

The configuration file will be loaded when nginx starts, changes done afterwards will not be loaded until you restart nginx or tell it to re-read it's configuration files.
# Restarts nginx using systemd (which will reload the configuration)
systemctl restart nginx
# Reload configuration without shutting down nginx
nginx -s reload
# or with systemd
systemctl reload nginx
# Test configuration without loading it
nginx -t
You can find more information about this in the nginx documentation.

Related

nginx config does not update after reload

following this tutorial :
https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-centos-7
I modified my config file /etc/nginx/sites-available/domainName by adding on the last row :
return 301 $scheme://www.example.com$request_uri;
Then I launched :
sudo systemctl restart nginx
It works well. Then I tried to modify www.example.com by my domain name and I launched again ;
sudo systemctl restart nginx
but it doesn't work, I'm still redirecting to example.com
I checked the log files, sudo nginx -t etc and everything looks good.
Do you have an idea of the problem?
Thanks
Try clearing the DNS cache in your pc, browser, and router.
If you're using Windows to run a Linux server in a virtual box, you can run the ipconfig /displaydns command to see the time of cache to live.

How to reload nginx in windows

I have installed nginx as a load balancer on my Windows machine using nssm. Now, I want to reload the configuration file of nginx for that I used nginx -s reload command but it is not working. It gives errors as access denied and I don't want to restart nginx. Is there any way to reload the nginx configuration file in windows.
Try following:
nssm restart nginx

Engintron: Nginx couldn't start

I have a Cpanel/WHM server with Nginx installed as reverse proxy (with default Nginx manager), so i tried to replace Nginx with Engintron.
I installed Engintron and uninstalled Nginx via Cpanel Nginx manager.
As a result i got website not working and Nginx couldn't start (status from WHM Engintron page), so i should reinstall Nginx?
I don't know if Engintron contains already Nginx or not
I tried to reinstall Nginx and website work again, but i don't know if Engintron is serving the website or Nginx
Engintron contains nginx installation within their script. So if you install only engintron, it will be default instead nginx in reverse proxy mode with apache.
You can check your nginx installed configuration file location by
sudo nginx -t
(it will show location of configuration file along with testing the same).
See if the nginx configuration file matches the engintron configuration file or not. If you are confused here also then run
$ sudo nginx -T
this will dump the output of configuration file which you may tally with Engintron config file.
Last option would be to uninstall both the nginx and make a clean installation of Engintron.
Try to run these commands first:
/usr/sbin/nginx -s stop
/usr/local/cpanel/scripts/restartsrv_nginx start
If the problem still exists, Uninstall Nginx and all Ruby packages from EasyApache via WHM and reinstall Nginx again.

File not found error from nginx on a virtual machine where /var/www/ is mounted from host file structure

I am trying to set up a rather complex development environment as a virtual Ubuntu 12.04 server.
In order that I can edit files and immediately see the change at the refresh of the page as you would expect with a normal local development situation, I have the php source code on the host operating system (mint 14) in ~/www/site1 which I have added as a persistent shared folder to virtualbox and then mount on the virtual machine
mount -t vboxsf site1 /var/www
if I ls /var/www -la I see all the php files but when I try to access the virtual machine from the browser, I get File not found errors on the page and the error.log for the subdomain reports FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream". The exception is the subdomain phpmyadmin.virtualmachine which loads up perfectly so I know that nginx is serving the correct file structure for the requested subdomain.
As a test I created a subdomain info.virtualmachine which points to /var/test and the index.php is the simplest phpinfo() and this works so I can only presume that nginx is not reading the mounted vboxsf file structure /var/www correctly as all "local" files on the guest OS are viewable.
Nginx has been configured to run as root as have all other services. Is this a known bug with nginx or something that I need to configure to allow nginx to see the mounted vboxsf share?
I found the answer to this and it turned out to be due to file permissions and my unfamiliarity of how php-fpm works.
For starters, I enabled the root user in the virtual server and using supervisord to control the daemons, I set them all to run as root. The parent process for php-fpm runs as root but all child processes were running as www-data. Mounting the share as root caused the folder to be unavailable to php-fpm's child processes which caused nginx to throw file not found errors and because of the way the vboxsf works, I was unable to chown or chmod the share.
I got around this issue by adding the share to /etc/fstab with the following command :
sharename /var/www vboxsf rw,uid=33,gid=33 0 0
this allowed the share to be mounted under the www-data user giving read permissions to www-data.

nginx virtual host - fail when restart with no error

I have several subdomains running on nginx, and when i added next one, there was a problem with the same name of subdomain i removed.
I'm not shure that config were worked in the past. This is what i have found on serwer.
For now there is no possibility to restart nginx with virtual hosts, becouse it's failed.
config tests is ok,
without vh's it is restarting well,
nginx.conf test is ok,
logs are clear
nginx config is placed in project and /etc/nginx is pointing to that folder
I have add that exaple vh and it is crushing event with it.
What else can i check, what may cause such a problem?
I have found solution. Nginx could not start after stop, becouse ports 80 and 433 were busy by... nginx. Anyway
netstat -tulpn
shown what process are runing on particular ports.
I killed these processes with commands:
sudo fuser -k 80/tcp and fuser -k 433/tcp
and after that
sudo service nginx start
just worked.
Config files are fine, and test pass, logs where clear and nginx command show whats wrong

Resources