Score:1

Nginx domain path issue

bt flag

I have the following domain fairgrounds.mohave.gov. If the users just type fairgrounds.mohave.gov I would like it to go to the following path:

https://fairgrounds.mohave.gov/parks/fairgrounds/

otherwise, just behave like normal. Here is the following configuration:

server {
            listen 80;
    #       listen 443;
            server_name fairgrounds.mohave.gov;
    #       return 301 https://$host$request_uri;
    #       return 301 https://fairgrounds.mohave.gov/parks/fairgrounds/;
            return 301 https://$host/$request_uri;
    }


server {
            listen 443 ssl http2;
            server_name fairgrounds.mohave.gov;

            root /var/www/parks2;

            index index.html index.htm index.nginx-debian.html;

            location / {
                    try_files $uri $uri/ =404;

                    add_header Last-Modified $date_gmt;
                    add_header Cache-Control 'no-store, no-cache, must_revalidate, proxy-revalidate, max-age=0';
                    if_modified_since off;
                    expires off;
                    etag off;
            }

    }        

I've tried several approaches showing the commented-out section in the sample above, but they don't seem to work. Any tips?

Score:1
jp flag

You need to externally redirect / to /parks/fairgrounds/ in the second server block.

Try:

server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl http2;
    server_name example.com;

    ...

    location = / {
        return 301 /parks/fairgrounds/;
    }    
    location / {
        ...
    }
}

The first location block only matches / and externally redirects visitors to https://example.com/parks/fairgrounds/. The second location block is your existing location block, and handles everything else. See this document for details.

bt flag
Perfect, thank you
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.