Answer the question
In order to leave comments, you need to log in
nginx: multiple hosts per index.php
There are several directories like /var/www/site_n/ that the virtual host looks at and contains user files and logs. There is a /usr/lib/cms/
directory with the CMS engine and an index.php file, which should be launched with a different environment depending on the host settings in nginx.
I'm trying to configure with this config using the example of one domain:
server {
server_name site1.com;
root /var/www/site1.com/public_html/;
set $app_root /usr/lib/cms/;
set $app_key 454647;
access_log /var/www/site1.com/logs/access.log;
error_log /var/www/site1.com/logs/error.log;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ $app_root/index.php?$args;
}
location ~ \.php$ {
try_files $uri @php;
fastcgi_pass php5-fpm-sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $app_root$fastcgi_script_name;
fastcgi_param app-key $app_key;
include fastcgi_params;
}
location @php {
fastcgi_pass php5-fpm-sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $app_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param QUERY_STRING q=$uri&$args;
include fastcgi_params;
}
}
Answer the question
In order to leave comments, you need to log in
I don't like your config.
Try like this:
location / {
index index.php index.html index.htm;
try_files $uri $uri/ @php;
}
location ~ \.php$ {
fastcgi_pass php5-fpm-sock;
fastcgi_index /;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param SCRIPT_FILENAME $app_root/index.php;
fastcgi_param app-key $app_key;
include fastcgi_params;
}
location @php {
fastcgi_pass php5-fpm-sock;
fastcgi_index /;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param SCRIPT_FILENAME $app_root/index.php;
fastcgi_param QUERY_STRING q=$uri&$args;
include fastcgi_params;
}
I understand the meaning of this action - saving on matches in the form of the absence of duplication of the code of the cms itself. At least you should not do this, because you cannot guarantee 100% that the cms version for each of the sites will be the same. As a last resort, make a symlink.
try_files $uri $uri/ $app_root/index.php ?$args The file has no parameters - that's why. But no one bothers to change this to try_files $uri php .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question