I learned by starting from a basic config file and figured things from there.
You should use http://nginx.org/en/docs/ to help you with this. Most things
are explained in http://nginx.org/en/docs/http/ngx_http_core_module.html.
Your main config file is /etc/nginx/nginx.conf and you don't really need any
other config files except for organizational purposes. Trisquel's nginx
installation comes with several predefined config files and directories in
/etc/nginx - I just remove them all and start from scratch.
When doing changes you can reload nginx with:
sudo nginx -s reload
Here's a very basic config file:
user www-data www-data;
events {
}
http {
default_type application/octet-stream;
autoindex on;
index index.html;
types {
"text/html; charset=utf-8" html;
"text/css; charset=utf-8" css;
"application/javascript; charset=utf-8" js;
"application/json; charset=utf-8" json;
image/png png;
image/jpeg jpg jpeg;
image/gif gif;
video/ogg ogv;
}
server {
server_name localhost;
root /srv/geshmy/www;
}
}
Here is what I pretty much use on my server:
user www-data www-data;
events {
}
http {
default_type application/octet-stream;
autoindex on;
index index.txt index.html;
types {
"text/html; charset=utf-8" html;
"text/css; charset=utf-8" css;
"application/javascript; charset=utf-8" js;
"application/json; charset=utf-8" json;
image/png png;
image/jpeg jpg jpeg;
image/gif gif;
video/ogg ogv
}
server {
# Lines used only if you want HTTPS:
listen 80;
listen 443 ssl;
server_name libtec.org www.libtec.org;
ssl_certificate /etc/ssl/private/libtec-cert.pem;
ssl_certificate_key /etc/ssl/private/libtec-key.pem;
root /home/mampir/web/libtec/www;
index index.html index.py;
# This is used if you want to work with Python CGI scripts.
# Similar blocks can be used for PHP, Ruby and etc. - see other
# example files on the web:
location ~ /index\.py$ {
include fastcgi_params;
fastcgi_param LANG en_US.UTF-8;
fastcgi_param PYTHONPATH /srv/libtec/lib;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
# This redirects http/https://www.libtec.org/bg/2013/gnu30/ to
# http/https://bg.libtec.org/2013/gnu30/.
location = /bg/2013/gnu30/ {
return 301 $scheme://bg.libtec.org/2013/gnu30/;
}
}
server {
listen 80;
listen 443 ssl;
server_name bg.libtec.org;
ssl_certificate /etc/ssl/private/libtec-cert.pem;
ssl_certificate_key /etc/ssl/private/libtec-key.pem;
root /home/mmp/web/libtec/bg/www;
# All lines bellow are used for FastCGI:
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REMOTE_ADDR $remote_addr;
location / {
# Use FastCGI when the requested URL does't lead to a file:
if (!-f $request_filename) {
fastcgi_pass unix:/tmp/fcgi-libtec.socket;
}
}
}
}