Nginx configuration

Léo Colombaro edited this page Jul 1, 2015 · 3 revisions

Nginx full support is an on-going and community driven effort. The server configuration can differ from one install to another, depending on your needs (and if you elect to run nginx you're supposed to be able to adapt the configuration based on these needs)

So far the most works-for-all configuration seems to be the following one:

server {

  # Listen IPv4 & v6
  listen 80;
  listen [::]:80;

  # Optional SSL stuff
  listen              443              ssl;
  listen              [::]:443         ssl;
  ssl_certificate     example.com.crt;
  ssl_certificate_key example.com.key;

  # Server names
  server_name example.com www.example.com;

  # Root directory (NEEDS CONFIGURATION)
  root /path/to/files;

  # Rewrites
  location / {

    # Try files, then folders, then yourls-loader.php
    # --- The most important line ---
    try_files $uri $uri/ /yourls-loader.php;

    # PHP engine
    location ~ \.php$ {
      try_files      $uri =404;
      fastcgi_pass   unix:/var/run/php5-fpm.sock; # Can be different
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
  }
}

If you experience problems with this config, or have any improvement or alternative to suggest, please join this discussion