L
L
Leonid2014-11-27 22:33:01
Nginx
Leonid, 2014-11-27 22:33:01

How to do rewriting in nginx from folder to folder?

Good day!
It costs Ubuntu Server 14.04.1
It has nginx 1.4.6 + PHP + MySQL + phpMyAdmin deployed on it.
I was given a task to which I must strictly adhere.
Here's the point I'm asking for help here:
You need to make a url rewrite rule so that when you access the
test1 folder , the test2 folder opens .
I created these folders in
/usr/share/nginx/html/ I
created them here, because it was this directory that the server accessed when it received http requests from the outside.
In the same directory there were 2 files:
index.html and 50x.html
zMiDJFvE.png
For rewriting, I changed the nginx.conf file located in /etc/nginx
zMiDJFvG.png
Under the "http" tag I added the following:

server {
     location = /for/test1 {
     rewrite ^(.*)$ /use/test2/$ break;
}
}

In each folder, I added an index.html with different content to see if the redirect would occur.
But no. When you enter 10.0.2.15/test1 in the address bar from another local machine , an html page opens, located exactly in the test1 folder.
Do not tell me how it would be correct to write a url rewrite rule for a given target?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Spetros, 2014-11-27
@Spetros

The paths specified in the rule do not match the described conditions. Now you have written that you need to overwrite test1 in the for folder. The next line has the same error.
Learn:
nginx.org/ru/docs/http/ngx_http_rewrite_module.html

E
Eugene, 2014-12-11
@Nc_Soft

Rewrite is not needed here
nginx.org/ru/docs/http/ngx_http_core_module.html#alias

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question