nginx config


Limp Gawd
Jul 4, 2012
I've got YOURLS server running to host short urls for my company, so that we can provide short URL's to our customers.

I'm using nginx, and for root of the domain, if they aren't using a proper short url I want to redirect to our website. So redirects to whatever that short url points to, but goes to our site.

Right now, I'm using an index.html page with just a meta refresh to redirect, but I was thinking I should be able to do that in the nginx config and it would likely be better.

Can someone help me with the proper way, if it's possible, to make that happen at the server level instead of using meta refresh?

Here is my config file for reference.

server {
	server_name [url];[/url]
	return 301 $scheme://$request_uri;

server {
	listen 80 default_server;
	listen [::]:80 default_server ipv6only=on;

	root /usr/share/nginx/html;
	index index.html index.htm index.php;

	# Make site accessible from [url]http://localhost/[/url]
	server_name [url];[/url]

	location / {
		try_files $uri $uri/ /yourls-loader.php;

	location ~ \.php$ {
    		try_files $uri =404;
    		include fastcgi_params;
    		fastcgi_pass php5-fpm-sock;
    		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    		fastcgi_intercept_errors on;