Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reuse server configurations in nginx?

When configuring nginx with a site that has ssl, the examples I find online basically duplicate the location settings. Most examples only have the default root location so it's not that big of a deal, but when you have a few locations and rewrite rules in place duplicating this configuration gets messy to maintain.

I've considered proxying the ssl requests to localhost to get around this, but that's kind of ugly. I've also considered using file includes, but the location configs for this site should be in 1 file since they are related.

Any suggestions?

Edit: We're using nginx version 0.6.32.

like image 900
Jack Chu Avatar asked Jun 26 '09 19:06

Jack Chu


People also ask

Can we have 2 NGINX on the same server?

Yes, its technically possible to install 2 nginx instances on the same server but I would do it another way. 1 - You could just create multiple EC2 instances.

How do I know if NGINX config is correct?

Through a simple command you can verify the status of the Nginx configuration file: $ sudo systemctl config nginx The output will show if the configuration file is correct or, if it is not, it will show the file and the line where the problem is.

What is keepalive in NGINX?

In Nginx, keepalive is a directive that is utilized for keeping the connection open for a certain number of requests to the server or until the request timeout period has expired.


1 Answers

There's a similar question on serverfault. Here's their answer:

server {
  listen 80;
  listen 443 default ssl;

  # other directives
}

The ssl parameter is included as of 0.7.14, which means we can't use it, but it's a good solution if you're on a newer version of nginx.

like image 88
Jack Chu Avatar answered Nov 15 '22 05:11

Jack Chu