nginx config

+Eric

Limp Gawd
Joined
Jul 4, 2012
Messages
128
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 example.com/218a redirects to whatever that short url points to, but example.com 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.

Code:
server {
	server_name [url]www.domain.com;[/url]
	return 301 $scheme://domain.com$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]http://domain.com;[/url]

	location / {
	        #YOURLS
		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;
    	}
}
 
Back
Top