Score:0

nginx location alias to root dir with another index file

it flag

i have 2 index file in root dir (index.php, thanks.php) and want to use thanks.php when user request other location, for ex: when user request example.com nginx show index.php,but when user request example.com/thanks nginx must show thanks.php i tryed this config, but it's not working for me:

server {
root /var/www/example.com;    
    index index.php;
    server_name example.com www.example.com;
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

location /thanks {
        alias /var/www/example.com;
        index thanks.php;
    }
}
Paul avatar
cn flag
There is a missing `;` should be `index thanks.php;` - is this in the actual server configuration file?
mocart avatar
it flag
fixed, but still not works
sv flag
alias doesn't work this way. Please check the docs at https://nginx.org/r/alias. You must be getting 301 for example.com/thanks. Instead of using a location block, I'd suggest `rewrite ^/thanks$ /thanks.php;`, if you are going to serve only one URL with thanks.php file.
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.