Skip to content

How to Install Yourls on Nginx

Install Yourls Nginx

To install Yourls on Nginx, the method is indeed easy and difficult. Ga like Apache which can be directly installed without any problems. Nginx requires additional at the time of setting in the Rewrite URL.

After you install Yourls using Nginx, you can add the following Rewrite URL script so that Yourls Shorten can run as expected.

Here are two codes that you can use, with a note yourls this is installed in the /go sub directory, so if you install it in the root directory, please delete the /go section.

Code 1 URL Rewrite Nginx

location /
{
	 try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

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

location ~ \.php$ {
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}

Code 2 URL Rewrite Nginx If Code 1 Not Works

location /
{
	 try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

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

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    include fastcgi_params;
  }
  
location ~ \.css {
    add_header  Content-Type    text/css;
    }
location ~ \.js {
    add_header  Content-Type    application/x-javascript;
}

That’s the tutorial on how to make Yourls Shorten work on a server with Nginx.