Nginx Raspberry Pi Configuration

This is more or less the configuration I am using for my installation of Nginx on a raspberry pi.

I compiled it with these options:
./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_spdy_module --with-file-aio --with-pcre-jit

I have disabled error logging by default, I only use nginx in debug mode if I can see any error.
Set it to a “safe” user and limit the number of processes to spawn.


error_log /dev/null crit;
user nobody;
worker_processes 1;
pid /var/run/nginx.pid;

Then the http configuration starts.
keepalive_timeout is set to 60 to allow some of my backend application to run and answer, the default value was causing the first try to fail while the application was loaded from swap or whatnot.

http
{
keepalive_timeout 60;
gzip on;

This is the server configuration. I enabled ssl and spdy disabling access logging, basic auth and set /var/www as the root folder.

server
{
listen 8080 default_server ssl spdy;
spdy_headers_comp 3;
access_log off;
auth_basic            "Restricted";
auth_basic_user_file  htpasswd;
ssl_certificate      /opt/nginx/cert.pem;
ssl_certificate_key  /opt/nginx/key.pem;
root /var/www;
index index.html;

Then I started adding the backend application that are reverse-proxy-ed by nginx (inside the server block).
Well, change app, host, and port to whatever you need.
The proxy timeout configuration is higher to avoid receiving errors too fast when the application is just.. slow.., and that happends quite easily with big python applications on a first gen raspberry pi

location /app {
proxy_pass          http://host:port;
proxy_set_header    X-Real-IP  $remote_addr;
proxy_read_timeout  300;
proxy_send_timeout  300;
}

And in case you also want to make accessible via http a part of your hard drive just add (always inside the server block)

location /mount {
autoindex on;
proxy_read_timeout 300;
proxy_send_timeout 300;
}

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: