0

To use the Nginx default conf (sites-available/default) one needs to uncomment all relevant lines in that file.

To avoid manual uncommenting each time I install a new server environment on a new machine, what I did was to make myself a copy of the uncommented default conf, and each time I just paste it, or redirect it (>), to the new default conf file, in the new machine.

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

The problem is that the above conf could change any day and if it changes tomorrow, it might mismatch a new Nginx I've installed with sudo apt-get install nginx on some machine.

Hence, I'm looking for a way to better cope with my need to turn on the default Nginx conf. I don't want to turn it on by manual uncommenting, or copy-paste a ready, uncommented version as I do now:

I aspire to turn on the default conf in a more safe way, maybe by some CLI command.

What will be a plausible way to do so?

  • I've no idea what your actual problem is, but I've a vague feeling that you have some big misunderstanding how all this is supposed to work. Also, normally you install nginx exactly once .... – Sven Feb 2 '18 at 11:54
  • What's "all of this"? With the above code I'm able to get Nginx to work and serve apps like PHPmyadmin. Without it, no app will work. I edited my question to better explain the problem I try to cope with. I am really surprised the question was putted on hold. – user454858 Feb 2 '18 at 12:03
  • In the mean time, here is my answer. You can define the configuration file with the "-c" option. Add DAEMON_OPTS variable to /etc/default/nginx. But I don't think an upgrade would overwrite your configurations changes without your permission. – Gerard H. Pille Feb 2 '18 at 12:05
  • I aspire to turn on the default conf in a more safe way. Removing/adding the symlink in sites-enabled is the default and safe and easy way on Debian/Ubuntu. – Sven Feb 2 '18 at 12:16
-2

You can define the configuration file with the "-c" option. Add the following line to /etc/default/nginx :

DAEMON_OPTS="-c  /thisismy.conf"

But I don't think an upgrade would overwrite your configurations changes without your permission.

  • 1
    I did, because that's a terrible approach, as you now ignored all the other stuff that gets included in the default config files on Debian/Ubuntu. There is an easy, standard and supported way to enable/disable configuration blocks like vhosts - just use it. – Sven Feb 2 '18 at 12:22
  • I thought the OP wanted his own "default.conf", and that's what the "-c" option is for. – Gerard H. Pille Feb 2 '18 at 12:54
  • No, the sites-available/default.conf on Debian/Ubuntu contains just a few defaults for virtual hosts, it gets included from the main config (/etc/nginx/nginx.conf file via an include statement that includes everything in sites-enabled. Everything in sites-enabled is supposed to be a symlink to a corresponding file in sites-available and you can activate/deactivate any block by removing or creating this symlink. – Sven Feb 2 '18 at 13:18
  • But @Sven the default file is still fully uncommented to be used, even if you add a symling to it from sites-enabled. My aim is to quickly uncomment the relevant conf inside it (in the end of it). – user454858 Feb 2 '18 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.