1

Using Nginx on FreeBSD, wondering what's the difference between

events {
    worker_connections 200;
}

and just worker_connections 200; by itself?

Or

server {
    listen 80;
    location / {
        return 301 https://$host$request_uri;
    }
}

vs

server {
    listen       80;
    return 301 https://$host$request_uri;
    location /two {
        return 301 https://something else?;
    }
}

I've seen both used on various examples. Are they interchangeable and only differ in scope?
Could I omit the http parent block, and only have the server blocks for example?

Thanks!

Oh and the specific file I've been editing is /usr/local/etc/nginx/nginx.conf

House3272
  • 169
  • 1
  • 5

1 Answers1

1

Syntax one is more useful if you're going to put multiple locations in a configuration, which would be typical. Syntax two is only for when you have a simple server returning a redirect or similar. Both of your examples will do the same thing.

Update Your updated second config will probably never execute the "location two" block due to the return at a higher level. You need quotes around the URL as well. You'd probably want something more like this

server {
  server_name example.com;
  listen       80;
  location / {
    return 301 https://$host$request_uri;
  }
  location /two {
    return 301 https://something else?;
  }
}
Tim
  • 31,888
  • 7
  • 52
  • 78