Rafa_F
May 30, 2013, 12:02pm
1
Hi,
new in ths nginx, with following config, I want to achieve:
http://sample.com/ render index.html
http://sample.com/test , or anything after ‘/’ path, render index.html
server {
listen 80;
server_name sample.com ;
root /var/www/sample/public_html;
location / {
index index.html index.htm;
}
location ~ ^/.* {
index index.html;
}
}
but when I do this, and got 404 error, anything missing here? Thanks
Angelo
curl -I http://sample.com/test
HTTP/1.1 404 Not Found
Posted at Nginx Forum:
Hi, new in ths nginx, with following config, I want to achieve: http://sample.com/ render index.html http://sample.com/test, or anything after '/' path, render index.html server { listen 80; server_name sample.com ;
Thanks for the reply, it works, and also I read again those references.
a
related issue, say:
if somebody enter this url in the browser:
http://sample.com/not_exist_url
and I’d like to redirect it to
http://sample.com/
with the try_files approach, index.html got displayed, that’s right, but
the
url in browser still remain as http://sample.com/not_exist_url , i’m
looking
for a 302 i believe, any suggestions? thanks.
Angelo
Posted at Nginx Forum:
Hi, new in ths nginx, with following config, I want to achieve: http://sample.com/ render index.html http://sample.com/test, or anything after '/' path, render index.html server { listen 80; server_name sample.com ;
On Thursday 30 May 2013 14:02:00 angelochen960 wrote:
Hi,
new in ths nginx, with following config, I want to achieve:
http://sample.com/ render index.html
http://sample.com/test , or anything after ‘/’ path, render index.html
server {
listen 80;
server_name sample.com ;
root /var/www/sample/public_html;
location / {
try_files /index.html =404;
}
}
index index.html;
Since your config looks incorrect, it seems you are missing
understanding of how
nginx works.
You should try to read documentation:
wbr, Valentin V. Bartenev
–
http://nginx.org/en/donation.html
On Thursday 30 May 2013 16:25:18 angelochen960 wrote:
the url in browser still remain as http://sample.com/not_exist_url , i’m
looking for a 302 i believe, any suggestions? thanks.
Yes, you’re looking for an external redirect, that is completely
different thing. Then this config will serve your needs:
server {
listen 80;
server_name sample.com ;
root /var/www/sample/public_html;
location = / {
try_files /index.html =404;
}
location / {
return 302 /;
}
}
Reference:
wbr, Valentin V. Bartenev
–
http://nginx.org/en/donation.html