0

I've read that it's not necessary to use sites-enabled, and even seen it suggested not to use.

In any case, its merit is not part of the question (so please consider that discussion off topic).

What I'm trying to do is set up an absolutely barebones basic nginx.conf file which does some super basic use case stuff: various forms of redirection.

By my understanding, this conf should be enough:

http {
  # default server
  server {
    root /var/www/html/production-site;

    # reverse proxy for external blog, makes example.com/blog display the blog.  helps with SEO.
    location /blog/ {
      proxy_pass https://example.some-external-blog.com/;
    }
  }

  # dev server
  server {
    server_name dev.example.com;
    root /var/www/html/dev-site;
  }
}

Unfortunately, my example doesn't work. The proxy bit works, but subdomains don't seem to. I don't honestly believe that server_name does anything at this point.

So, how does one write a simple (no extras) nginx.conf file which will exemplify these super trivial functionalities (subdomains and reverse proxies)?

Seph Reed
  • 8,797
  • 11
  • 60
  • 125

1 Answers1

1

I tried your config at my sandbox VM. nginx refuses to start, and when I run nginx -t command (which is always a good idea after significant configuration change), it says:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] no "events" section in configuration
nginx: configuration file /etc/nginx/nginx.conf test failed

So I've added events {} line to the config. After that nginx successfuly starts and all is working as expected.

Another thing that I wouldn't skip is including mime.types file. So final minimal configuration would look as follows:

events {}

http {
  include mime.types;

  # default server
  server {
    root /var/www/html/production-site;

    # reverse proxy for external blog, makes example.com/blog display the blog.  helps with SEO.
    location /blog/ {
      proxy_pass https://example.some-external-blog.com/;
    }
  }

  # dev server
  server {
    server_name dev.example.com;
    root /var/www/html/dev-site;
  }
}
Ivan Shatsky
  • 13,267
  • 2
  • 21
  • 37
  • Thank you. By having a minimal config example, it is much easier to understand what factors -- having started with the much less minimal default config -- are contributing to the system. – Seph Reed Nov 15 '19 at 17:04