L
L
lapka-admin2018-02-07 15:29:50
Nginx
lapka-admin, 2018-02-07 15:29:50

How to add condition in apache and nginx?

It is now written:

<VirtualHost 222.222.222.222:8080>
    ServerName site.ru
    ServerAlias www.site.ru
    DocumentRoot /home/user/web/site.ru/public_html/my/www
    ...
</VirtualHost>

First question: how to write a condition:
If the site address starts with site.ru/catalog
Then send a request not to www but to xxx:
DocumentRoot /home/user/web/site.ru/public_html/my/xxx
Second question: where is it correct write (in the same VirtualHost block? Otherwise, the first rule with sending to www will work above?) and whether you need to touch the ServerAlias ​​alias and also write www.site.ru/catalog*** for it
And the same question for nginx, there now:
server {
    listen      222.222.222.222:80;
    server_name site.ru www.site.ru;
    error_log  /var/log/apache2/domains/site.ru.error.log error;

    location / {
        proxy_pass      http://222.222.222.222:8080;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|od$
            root           /home/user/web/site.ru/public_html/my/www;
            access_log     /var/log/apache2/domains/site.ru.log combined;
            access_log     /var/log/apache2/domains/site.ru.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pyanov, 2018-02-15
@gohdan

According to Apache, I would do it not in the host settings, but by rewriting in .htaccess.
For nginx - via location:
location /catalog/ {
root /home/user/web/site.ru/public_html/my/xxx
....
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question