A
A
Alexey Voropaev2018-11-05 08:41:05
Nginx
Alexey Voropaev, 2018-11-05 08:41:05

How to make a universal nginx site config?

My default server
server {
  listen 80 default_server;
  listen [::]:80 default_server;

  root /home/alexey/sites/$http_host;

  index index.php index.html index.htm index.nginx-debian.html;

  server_name $http_host;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
  }
  
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
  
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
  }

  location ~ /\.ht {
    deny all;
  }
}

I just add the domain to /home/alexey/sites, to hosts and it works.
I want to make sure that if the domain starts with symfony, then the root directory should be public
How to do this?
If I replace $http_host with the domain name and add the path to the public directory to root, then everything works, but I want to make a universal setting for all sites
Examples:
domain: test.local
root: /home/alexey/sites/test.local
domain: symfonytest.local
root: /home/alexey/sites/symfonytest.local/public

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Softer, 2018-11-05
@boomrap

I think it's worth using map
here. For default, the variable will be empty, for "~^symfony" - "/public". And then glue it to root.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question