B
B
Bastax132017-05-19 01:01:49
Nginx
Bastax13, 2017-05-19 01:01:49

Location in NGINX?

I've been suffering for 3 days, I tried different options - all in vain. The last hope is for you)
How to implement locations in nginx like this:

mysite.com               ->  /var/www/main
mysite.com/любой_текст   ->  /var/www/qwerty

DECISION
Thanks to everyone (in particular @Lynn ).
server {
    root /var/www/qwerty;
    location = / {
        root /var/www/main;
        rewrite ^ /index.html break;
    }
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
Lynn "Coffee Man", 2017-05-19
@Bastax13

Judging by the comments, nothing works for you because you need the index.html file, not just /var/www/main and you forgot that the index module does an internal redirect.
This is how it should work:

server {
  root /var/www/qwerty;
  location = / {
    root /var/www/main;
    rewrite ^ /index.html break;
  }

A
Andrey Burov, 2017-05-19
@BuriK666

location = / {root /var/www/main;}
location / {root /var/www/qwerty;}

D
dummyman, 2017-05-19
@dummyman

I don’t even remember, somewhere I saw among the software for monitoring the setting of hosts, rights and other nginx configs through the browser.
Check out pcp.io or munin . In general, nginx configs can be easily generated by yourself, just take a sample from /etc/nginx and put everything in /etc/nginx/conf.d.
And after all the changes service nginx restart.
The script for bash is elementary, you can throw it in an hour using only sed and perl or even on awk, it will work no worse than Denver.

D
Dmitry MiksIr, 2017-05-19
@miksir

location = / {
  root /var/www/main;
  try_files /index.html =404;
}

location / {
  /var/www/qwerty;
  try_files /index.html =404;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question