我刚刚完成了将我的Symfony应用程序拆分为多个应用程序的操作,具体操作如下:https://symfony.com/doc/current/configuration/multiple_kernels.html
在底部写着Additionally, you might need to update your web server configuration to set the APP_ID=admin under a different domain.
。我该怎么做?
我在本地机器上使用Apache,我的服务器使用NGINX。
我当前的Apache本地配置:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/alexandra/dev/Web/PROJECT/public
<Directory /Users/alexandra/dev/Web/PROJECT/public>
Require all granted
AllowOverride None
DirectoryIndex index.php
Options -Indexes
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
</Directory>
</VirtualHost>
下面是NGINX的服务器配置:
server {
server_name ...
listen 443 ssl;
ssl_certificate ...
ssl_certificate_key ...
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
root /var/www/PROJECT/public/;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log ...
access_log ...
}
1条答案
按热度按时间2q5ifsrm1#
首先我必须说的是,很少需要拆分应用程序。如果你认为不同的应用程序需要相同的bundle/libraries和相同的
config.yaml
设置,那么我首先想到的不是像这样拆分应用程序。通常情况下,如果你需要不同的前端和管理用户,你可以通过为不同的防火墙定义不同的UserProvider来分割它,该防火墙监听
/admin
子路径上的所有内容。但我想回答你的问题
有几种方法,但我认为最简单的是使用
SetEnv
apache指令,这里有文档:https://httpd.apache.org/docs/2.4/mod/mod_env.html。唯一的要求是你的web服务器必须安装mod_env apache模块。然后你可以使用
SetEnv
指令设置你的apache配置。也有其他方法,但它们需要您自定义
Kernel.php
文件。例如每个域加载不同的.env
文件,或更改APP_ID
变量以后缀域。可能有更多方法,但我认为SetEnv
指令是最好的方法。