Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload Nginx configuration

I am trying to modify the Nginx config file to remove a "rewrite".

Currently, I have this config file:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen      80;
        server_name amc.local;
        return 301 https://$host:8443/index.html;
    }
}

Now I want to reload this config file, I tried

nginx -s reload
nginx -c <conf file>
nginx -s stop/start

In the log file, there is the line

2014/01/22 11:25:25 [notice] 1310#0: signal process started

but the modifications are not loaded.

like image 968
dev691 Avatar asked Jan 22 '14 19:01

dev691


People also ask

Does nginx auto reload config?

nginx -t will test the syntax of the configuration files and ensure that all configuration files referenced are accessible. If the Nginx configuration passes testing, then Nginx will be reloaded with nginx -s reload .

Do I need to restart nginx after config change?

You need to reload or restart Nginx whenever you make changes to its configuration. The reload command loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.

How does nginx reload work?

Nginx ReloadApplies new configuration, that is, to open log files and new listen sockets. If this fails, it rolls back changes and continues to work with old configuration. If this succeeds, it starts new worker processes, and sends messages to old worker processes requesting them to shut down gracefully.

When should I restart nginx?

Restart Nginx only when making significant configuration updates, such as changing ports or interfaces. This command will force shut down all worker processes.


Video Answer


2 Answers

Maybe you're not doing it as root?

Try sudo nginx -s reload, if it still doesn't work, you might want to try sudo pkill -HUP nginx.

like image 106
cnst Avatar answered Oct 21 '22 19:10

cnst


If your system has systemctl

sudo systemctl reload nginx

If your system supports service (using debian/ubuntu) try this

sudo service nginx reload

If not (using centos/fedora/etc) you can try the init script

sudo /etc/init.d/nginx reload
like image 33
Mohammad AbuShady Avatar answered Oct 21 '22 19:10

Mohammad AbuShady