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.

Apr 302011
 

Enable Expire header in Nginx

Answer:

Enabling Expire header for static contents is useful to reduce the loading of your web server.

If you are using nginx, it is easy by adding the following lines in your nginx.conf

location ~* \.(ico|css|js|gif|jpe?g|png)$ {
    expires max;
}

So all files with the above extensions will be delivered with the maximum expire header.

If you want user to update the cached contents, make sure you have change the path (i.e. rename) of these resources.

Dec 172010
 

How to change the nginx log format?

Answer:

Firstly, you need to define a valid log format for nginx, e.g.

log_format foo '$remote_addr - $remote_user [$time_local]  '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent"';

Then, you need to link that format with your log file:

access_log /var/logs/nginx-test-access.log foo;

Aug 142010
 

Enable gzip compression in Nginx

Answer:

Enabling gzip compression for text based output such as HTML can greatly improve the response of user.

If you are using nginx, it is easy by adding the following lines in your nginx.conf

gzip  on;
gzip_min_length  1000;
gzip_proxied     expired no-cache no-store private auth;
gzip_types text/plain text/html text/css application/json application/x-javascript text/javascript text/xml application/xml;
Apr 102010
 

Installing Nginx in Ubuntu

Answer:

1. Using aptitude

# sudo aptitude install nginx

2. Start it

# sudo /etc/init.d/nginx start

3. Stop it

# sudo /etc/init.d/nginx stop

4. Restart it

# sudo /etc/init.d/nginx restart

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