A
A
Alexey Yarkov2017-02-05 09:50:31
Nginx
Alexey Yarkov, 2017-02-05 09:50:31

How to redirect from a subdomain to a directory using Nginx?

Very short config, only important:

upstream keeper_app {
    server 127.0.0.1:8080;
}

server {
    listen 80;
    server_name domain.dev www.domain.dev;
    proxy_set_header Host domain.dev;
    access_log  /var/log/nginx/domain.ru/access.log combined;
    error_log  /var/log/nginx/domain.ru/error.log  warn;
    resolver 127.0.0.1;
    root /var/www/domain.ru;
    index index.html;
    location / {
        try_files $uri $uri/ /index.html;
    }
    location /api/ {
        proxy_pass http://keeper_app;
    }
}

Forwarding view requests http://domain.ru/api/(.*)to the Node.js server works. And how to make requests look like api.domain.ru/(.*) ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry MiksIr, 2017-02-05
@yarkov

server {
    listen 80;
    server_name api.domain.dev;

    location / {
        proxy_set_header Host domain.dev;
        proxy_pass http://keeper_app/api/;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question