Permanent Redirect on nginx

Dear Nginx Community

My org has changed domain from unam.na to unam.edu.na. I intend to
effect a permanent redirect on Nginx.

I have tried the lines in bold below but browsers are complaining of too
many redirects.

Any tips on how I can adjust the config file for permanent redirect?

-----------------------Complete config file under
sites-enabled---------------------------------------

server {

listen 80;
root /usr/share/nginx/atom;

http://wiki.nginx.org/HttpCoreModule#server_name

_ means catch any, but it’s better if you replace this with your

server

name, e.g. archives.foobar.com

server_name _;
#server_name archives.unam.na;
#return 301 $scheme://archives.unam.edu.na;

#server_name archives.unam.na;
#rewrite ^ http://archives.unam.edu.na$request_uri? permanent;

client_max_body_size 72M;

http://wiki.nginx.org/HttpCoreModule#try_files

location / {
try_files $uri /index.php?$args;
}

location ~ /. {
deny all;
return 404;
}

location ~* (.yml|.ini|.tmpl)$ {
deny all;
return 404;
}

location ~* /(?:uploads|files)/.*.php$ {
deny all;
return 404;
}

This is the most important part, as here we are redirecting some

specific

requests to PHP-FPM so PHP can do its job passing data to and from

the

web server.

location ~ ^/(index|qubit_dev).php(/|$) {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.atom.sock;
}

location ~* .php$ {
deny all;
return 404;
}

}

On Thu, Apr 28, 2016 at 02:47:03PM +0000, Mumanyi, Bravismore wrote:

Hi there,

My org has changed domain from unam.na to unam.edu.na. I intend to effect a
permanent redirect on Nginx.

Have two server{} blocks.

The one with “server_name new-name;” should be the fuller one, doing
everything you want.

The other should have “server_name old-name;” and “return 301
http://new-name$request_uri;” and not a lot more.

f

Francis D. [email protected]

Francis, your config did magic! Kudos…

However, I just wondering the cause for the redirect URL having two
trailing slashes “//” i.e. “http://archives.unam.edu.na//”? The links
seem to work though.

The two server blocks are as follows.

server {
listen 80;
listen 443 ssl;
server_name archives.unam.na;
return 301 $scheme://archives.unam.edu.na$request_uri;
}

server {

listen 80;
listen 443 ssl;
root /usr/share/nginx/atom;

http://wiki.nginx.org/HttpCoreModule#server_name

_ means catch any, but it’s better if you replace this with your

server

name, e.g. archives.foobar.com

#server_name _;
server_name archives.unam.edu.na;

Regards

On Fri, Apr 29, 2016 at 07:33:04AM +0000, Mumanyi, Bravismore wrote:

Hi there,

Francis, your config did magic! Kudos…

Good to hear you have it working, thanks.

However, I just wondering the cause for the redirect URL having two trailing
slashes “//” i.e. “http://archives.unam.edu.na//”? The links seem to work though.

If you are reporting that

curl -i http://archives.unam.na/

returns a http 301 with a Location: header of
http://archives.unam.edu.na// then that’s not what I expect and that’s
not what I observe.

If you’re reporting something else that is repeatable when there is no
extra caching in the browser, for example, then the curl command that
shows the request and response will be helpful.

Cheers,

f

Francis D. [email protected]