U
U
uSide2014-08-28 14:36:47
PHP
uSide, 2014-08-28 14:36:47

How to match and transfer a domain in nginx?

Those. I, for example, have a bunch of domains like sitename.general.ru, where the sitename is different.
How to match this part and transfer it to php-fpm?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Petrikov, 2014-08-28
@uSide

Instead of slang, would you like to describe the task in a human way, to match it in your understanding, do you want to compare them or what? Or you need to pass only the third level domain, if so, then through variables, something like this:

map $host $host_wo_www {
        default $host;
        ~^www\.(?P<wo_www>.+)$ $wo_www;
    }

server {

    server_name ~^(?:www\.)?(?P<host_wo_www>.+)$;
    server_name_in_redirect     off;
    resolver    127.0.0.1;

root /var/www/$host_wo_www;

#Передавать на php-fpm примерно так, тут пример передачи для апача, для передачи на php-fpm суть та-же в принципе.

location / {
   proxy_redirect     off;
   proxy_set_header   Host             $host_wo_www;
   proxy_set_header   X-Real-IP        $remote_addr;
   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
   proxy_buffers 8 2m;
   proxy_buffer_size 10m;
   proxy_busy_buffers_size 10m;
   proxy_pass http://backend; # В качестве бэкенда вешайте что нравится.
   }

I myself once asked a similar question, here: Help with a regular expression for nginx

V
Vlad Zhivotnev, 2014-08-29
@inkvizitor68sl

https://debian.pro/558
Somehow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question