F
F
Fireproof Cockroach2018-12-19 10:02:04
Nginx
Fireproof Cockroach, 2018-12-19 10:02:04

How to setup folder and domain in nginx?

Hey!
Available:

  • View subdomainbla-stage.domain.tld
  • Folder/var/www/bla

How to configure root so that nginx will look for a non-postfix domain -stage?
Examples:
  • feature-next-stage.domain.tld/var/www/feature-next
  • feature-bla-stage.domain.tld/var/www/feature-bla

Tried, didn't work.
server {
    listen   80 default_server;
    charset  utf-8;
    server_name "~^(.*)-stage\.domain\.tld$";
    root /var/www/$1;
    index index.html index.htm index.php;
    ...
}

Any ideas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-12-19
@uonick

server {
    listen 80;
    server_name ~^(?<root_dir>.*)-stage\.domain\.tld$;
    root /var/www/$root_dir;
    ...
}

A
Andrey Yumashev, 2018-12-19
@skazkin

server {
  listen 80;
  server_name   ~^([^\-]+\-[^\-]+)\-stage.domain.tld$;

  if ($host ~* ^([^\-]+\-[^\-]+)\-stage.domain.tld$) {
    set $root_dir $1;
  }

  location / {
    root /var/www/$root_dir
  }
}

This is a bit of a crutch in Nginx - this is an example of an adapted working config - but the point is clear. We need to set variables. $1 just won't work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question