Nginx configuration

Léo Colombaro edited this page Jan 23, 2018 · 8 revisions

What your yourls.conf file for YOURLS should look like.

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).

The basic Nginx server configuration

server {

  # HTTP over IPv4 & IPv6
  listen 80;
  listen [::]:80;

  # HTTPS over IPv4 & IPv6
  # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
  listen 443 ssl;
  listen [::]:443 ssl;
  ssl_certificate     example.com.crt;
  ssl_certificate_key example.com.key;

  # Server names
  # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
  server_name example.com www.example.com;

  # Root directory
  # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
  root /path/to/yourls/files;

  # Rewrites
  location / {
    try_files $uri $uri/ /yourls-loader.php$is_args$args;
  }

  # PHP engine
  location ~ \.php$ {
    include fastcgi.conf;
    # OR
    # include fastcgi_params;
    
    fastcgi_index index.php;
    
    # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  }

}

Bonus tricks

You may look at H5BP Server Configs for tricks and tips regarding your Nginx global file configuration. This may suit your needs or improve your overall experience.