I would like to configure the Nginx web-server in such a way that:
/index.php
URI should be handled by public_html/frontend/web
Here's my working config, based on accepted answer. My project backend
directory is renamed to admin
# Example config for nginx
# frontend is available on yii-application.local/
# backend (admin) is available on yii-application.local/admin
# make sure that @app/frontend/config/main.php and @app/admin/config/main.php components sections are configured properly
# e.g. @app/frontend/config/main.php
# 'homeUrl' => '',
# ...
# 'components' => [
# 'request' => [
# 'baseUrl' => '',
# ],
# 'urlManager' => [
# 'enablePrettyUrl' => true,
# 'showScriptName' => false,
# ],
# ]
#
# e.g. @app/admin/config/main.php
# 'homeUrl' => '/admin',
# ...
# 'components => [
# 'request' => [
# 'baseUrl' => '/admin',
# ],
# 'urlManager' => [
# 'enablePrettyUrl' => true,
# 'showScriptName' => false,
# ],
# ]
server {
set $project_root /home/yii/apps/yii-advanced;
set $fcgi_server unix:/opt/php/var/run/php5-fpm.sock;
charset utf-8;
client_max_body_size 128M;
listen 80;
server_name yii-application.local;
root $project_root/frontend/web;
index index.php;
access_log /home/yii/apps/yii-advanced/logs/access-backend.log;
error_log /home/yii/apps/yii-advanced/logs/error-backend.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /admin {
index /web/index.php;
alias $project_root/admin/web;
try_files $uri $uri/ /web/index.php?$args;
location ~ ^/admin/.*\.php$ {
rewrite ^/admin/(.*)$ /web/$1;
fastcgi_pass $fcgi_server;
include fastcgi.conf;
}
}
location ~ ^/web/.*\.php$ {
internal;
root $project_root/admin;
fastcgi_pass $fcgi_server;
include fastcgi.conf;
}
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass $fcgi_server;
include fastcgi.conf;
}
location ~* \.(htaccess|htpasswd|svn|git) {
deny all;
}
}