Thursday, April 13, 2017

301 redirects in nginx on laravel homestead

I'm trying to configure some 301 permanent redirects for some pages that have been moved (to a sub-folder of '/local'). My local environment, the test server and the live server all run on nginx, which I am new to. My local environment is set up with Homestead and I am trying to get the redirects to work there first.

I have ssh'd to my homestead vm, and edited the file /etc/nginx/nginx.conf: I have added this server block within the http block:

    server {
        server_name local.kkds;

        location /essex {
            rewrite ^/essex(.*)$ /local/essex$1 permanent;
        }
    }

When I include the server_name and do sudo nginx -s reload, I get the message nginx: [warn] conflicting server name "local.kallikids" on 0.0.0.0:80, ignored The urls redirect but all pages display an nginx 404 page, except the homepage which displays 'Welcome to nginx' page.

If I comment out the server_name the rest of the site works as it should but the redirects don't happen. I also tried replacing the server name with ip address in my homestead.yaml file and with 0.0.0.0 but still the redirect are not happening.

Perahps I am placing the configuration in the wrong place? Can someone point me in the right direction?



via ellcub

Advertisement