#nginx #yii2
#nginx #yii2
Вопрос:
Я создал и разрабатываю свое приложение yii на сервере apache, и вся конфигурация хорошо работает на apache, но теперь я пытаюсь развернуть свой проект на новом сервере с nginx, но доступна только домашняя страница. любая другая ссылка, по которой я нажимаю, получает страницу 404, которая не найдена. Я использовал приведенный ниже .htaccess для своих правил перезаписи в apache и теперь ищу что-то, что делает то же самое в nginx
RewriteEngine On
# deal with admin first
RewriteCond %{REQUEST_URI} ^/myweb/(admin)
RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]
RewriteRule ^admin/images/(.*)$ backend/web/images/$1 [L]
RewriteRule ^admin/img/(.*)$ backend/web/img/$1 [L]
RewriteRule ^admin/plugins/(.*)$ backend/web/plugins/$1 [L]
RewriteRule ^admin/uploads/(.*)$ backend/web/uploads/$1 [L]
RewriteCond %{REQUEST_URI} ^/myweb/(admin)
RewriteRule ^.*$ backend/web/index.php [L]
RewriteCond %{REQUEST_URI} ^/myweb/(assets|css)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^plugins/(.*)$ frontend/web/plugins/$1 [L]
RewriteRule ^imgages/(.*)$ frontend/web/images/$1 [L]
RewriteRule ^img/(.*)$ frontend/web/img/$1 [L]
RewriteRule ^item_img/(.*)$ frontend/web/item_img/$1 [L]
RewriteRule ^uploads/(.*)$ frontend/web/uploads/$1 [L]
RewriteRule ^itemImg/(.*)$ frontend/web/itemImg/$1 [L]
RewriteCond %{REQUEST_URI} !^/myweb/(frontend|backend)/themes/
RewriteCond %{REQUEST_URI} !^/dajubet/(frontend|backend)/web/(uploads|img|item_img|itemImg)/
RewriteCond %{REQUEST_URI} !^/dajubet/(frontend|backend)/web/(assets|css|js|plugins)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
и мой конфигурационный файл интерфейса и серверной части, как показано ниже, соответственно
frontend config file
return [
'id' => 'app-frontend',
//'language' => 'zh-CN',
'name' => 'dajubetFrontend',
'basePath' => dirname(__DIR__),
'defaultRoute'=>'home/index',
'bootstrap' => ['log'],
'controllerNamespace' => 'frontendcontrollers',
'components' => [
'request' => [
'csrfParam' => '_csrf-frontend',
'class' => 'commoncomponentsRequest',
'web'=> '/frontend/web',
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'advanced-frontend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yiilogFileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'home/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:w >/<id:d >' => '<controller>/view',
'<controller:w >/<action:w >/<id:d >' => '<controller>/<action>',
'<controller:w >/<action:w >' => '<controller>/<action>',
'<members:w ><payment:w >/<test:[^/]*>/*' => '<controller>/view'
//'<members:w >/<payment:w >/<action:w >/<id:d >' => '<controller>/<action>/views',
//'<members:w ><payment:w >/<test:[^/]*>/*' => '<controller>/view'
],
],
],
'as beforeRequest' => [
'class' => 'commoncomponentsLanguageHandler',
],
'params' => $params,
];
backend config file
return [
'id' => 'app-backend',
//'language' => 'zh-CN',
'name' => 'dajubetBackend',
'defaultRoute'=>'home/index',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backendcontrollers',
'bootstrap' => ['log'],
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'class' => 'commoncomponentsRequest',
'web'=> '/backend/web',
'adminUrl' => '/admin'
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yiilogFileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'home/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:w >/<id:d >' => '<controller>/view',
'<controller:w >/<action:w >/<id:d >' => '<controller>/<action>',
'<controller:w >/<action:w >' => '<controller>/<action>',
],
],
'authManager' => [
'class' => 'yiirbacDbManager',
'defaultRoles' => ['users'],
],
],
'as beforeRequest' => [
'class' => 'commoncomponentsLanguageHandler',
],
'params' => $params,
];
и, наконец, мой файл конфигурации сервера nginx
server {
set $project_root /var/www/myweb.com/html/dajubet;
set $fcgi_server unix:/run/php-fpm/www.sock;
charset utf-8;
client_max_body_size 128M;
listen 80;
listen [::]:80;
root $project_root/frontend/web;
index index.php index.htmli index.htm index.nginx-debian.html;
server_name myweb.com www.myweb.com;
location ^~ /admin {
rewrite ^/backend(.*)$ /backend/web$1 last;
}
location ^~ /backend/web {
root $project_root;
# uncomment the following, if you want to enable speaking URL in the backend
try_files $uri $uri/ /backend/web/index.php$is_args$args;
location ~ /.(ht|svn|git) {
deny all;
}
location ~ .php$ {
try_files $uri =404;
try_files $uri =404;
include fastcgi_params;
fastcgi_pass $fcgi_server;
}
}
# location / {
# try_files $uri $uri/ /index.php$is_args$args;
# }
location ~ /.(ht|svn|git) {
deny all;
}
location ~* .php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location / {
try_files $uri $uri/ =404;
}
access_log /var/log/nginx/myweb.com.access.log;
error_log /var/log/nginx/myweb.com.error.log;
}
Любая помощь в решении этой проблемы была бы оценена, спасибо вам, ребята