Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 302010
 

Adding SSL suport in Nginx

Answer:

Assume you have got your certificate file (server.crt) from a CA, and you also have a private key (server.key).

1. Compile Nginx to support SSL

# ./configure --with-http_ssl_module

2. Add the following line in nginx.conf

server {
    server_name YOUR_DOMAINNAME_HERE;
    listen 443;
    ssl on;
    ssl_certificate /usr/local/nginx/conf/server.crt;
    ssl_certificate_key /usr/local/nginx/conf/server.key;
}

3. Restart Nginx

Reference: http://wiki.nginx.org/NginxHttpSslModule

Mar 102010
 

How many worker_processes should I use in Nginx?

Answer:

In the Nginx configuration (nginx.conf), the default worker_processes is 1.

e.g.

worker_processes  1;

However, as nowadays most servers are multi-core/multi-processor machine, it is a waste to only use 1 worker process.

The recommended worker_processes is equal to the number of CPU cores, e.g. if you have a dual Quad Core server, you should set to 8.

worker_processes  8;
Feb 092010
 

How to define variable in nginx

Answer:

nginx provided a very simple way to define custom variable, which can provide a very flexible way to control your web server.

E.g.

set $foo bar; 

if ($foo ~ bar) {
    # do something  
}

Feb 092010
 

Add custom HTTP header by nginx

Answer:

To inject custom HTTP header into the HTTP response, is very easy with nginx.

Add the following line into the configuration (add into the location you need):

E.g.

location / {
    add_header Foo Bar;
}