73

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.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
dev691
  • 1,034
  • 1
  • 9
  • 17

2 Answers2

120

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.

cnst
  • 25,870
  • 6
  • 90
  • 122
  • 1
    Even on Bitnami LAMP Stack, this method is working! Thank you – Jamaluddin Rumi Jul 24 '16 at 16:41
  • @GangsarSwaPurba, glad it works! It should work pretty much on any UNIX system, since it does not depend on any proprietary frameworks or system-specific scripts! – cnst Jul 24 '16 at 16:48
53

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
Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
  • 2
    An equivalent without service is `/etc/init.d/nginx reload`. Would work on centos and debian as far as i know. – Lightbulb1 Jun 24 '14 at 13:39
  • debian distros prefer the `service` keyword, some packages even give a warning if you use the `init.d` script, so I usually use the `service` and fall back to `init.d` if it doesn't work, either ways I'll add this tip to my answer – Mohammad AbuShady Jun 24 '14 at 13:41
  • Thats interesting. I've never seen a warning. I always thought service ran the scripts in /etc/init.d/. I prefer service because its easier to type. Whats the technical reason for there being a warning thrown? – Lightbulb1 Jun 24 '14 at 13:47
  • Thank you. That makes allot of sense. Also i found this [http://www.tutorialspoint.com/unix_commands/service.htm](http://www.tutorialspoint.com/unix_commands/service.htm) i think its just the man pages, but it does explain how service create a minimal environment to run the scrips in. I guess it can help them run consistently between different distros. – Lightbulb1 Jun 24 '14 at 13:57
  • It would work when you have a service for Nginx. The question is about the Nginx execution file not a service one... – Ario Nov 18 '16 at 14:36