H
H
harmoon2022-03-16 19:46:24
Nginx
harmoon, 2022-03-16 19:46:24

NGINX proxying all pages except the home page?

Set up Nginx to proxy another site.
I want the proxied site to be displayed when visiting any page, but apart from the MAIN page, i.e. when a person enters the main page, an index file from the site folder was displayed.
What should be written in the location? Tried location = / {...}it doesn't work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2022-03-16
@harmoon

nginx.org/ru/docs/http/ngx_http_index_module.html#index

Keep in mind that when using an index file, an internal redirection is made and the request may be processed in another location.

So index index.html;try_files is needed instead.
location = / {
    try_files /index.html =404;
}

location / {
    proxy_pass ...;
}

Or rewrite with the break flag.
location = / {
    rewrite ^ /index.html break;
}

location / {
    proxy_pass ...;
}

K
ky0, 2022-03-16
@ky0

You need two locations, = /and just /. The first one will process the main page, the second - everything else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question