Не могу правильно сформировать конфиг nginx
у меня есть такой конфиг для сайта
server {
listen 100.100.100.100;
server_name site.com www.site.com;
set $base_root /home/admin/web/site.com/public_html;
root $base_root;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/site.com.log combined;
access_log /var/log/nginx/domains/site.com.bytes bytes;
error_log /var/log/nginx/domains/site.com.error.log error;
ssl on;
ssl_certificate /home/admin/conf/web/ssl.site.com.pem;
ssl_certificate_key /home/admin/conf/web/ssl.site.com.key;
location / {
root $base_root/frontend/web;
index index.php index.html;
try_files $uri $uri/ /frontend/web/index.php$is_args$args;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
}
location /admin {
alias $base_root/backend/web/;
try_files $uri /backend/web/index.php$is_args$args;
location ~ ^/admin/assets/.+\.php(/|$) {
deny all;
}
}
location ~ ^/.+\.php(/|$) {
rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;
fastcgi_param SCRIPT_FILENAME $request_filename;
if (!-f $request_filename) {
return 500;
}
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ /\. {
deny all;
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/admin/web/site.com/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/admin/web/site.com/stats/;
include /home/admin/conf/web/site.com.auth*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/snginx.site.com.conf*;
}
Сам сайт написан на yii2 advanced. Все хорошо работает. Но стала задача создать api в проекте. Я сделал папку api и хочу сделать, что бы запросы /api смотрели в нее. Сделал по принципу /admin
server {
listen 100.100.100.100;
server_name site.com www.site.com;
set $base_root /home/admin/web/site.com/public_html;
root $base_root;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/site.com.log combined;
access_log /var/log/nginx/domains/site.com.bytes bytes;
error_log /var/log/nginx/domains/site.com.error.log error;
ssl on;
ssl_certificate /home/admin/conf/web/ssl.site.com.pem;
ssl_certificate_key /home/admin/conf/web/ssl.site.com.key;
location / {
root $base_root/frontend/web;
index index.php index.html;
try_files $uri $uri/ /frontend/web/index.php$is_args$args;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
}
location /admin {
alias $base_root/backend/web/;
try_files $uri /backend/web/index.php$is_args$args;
location ~ ^/admin/assets/.+\.php(/|$) {
deny all;
}
}
location /api {
alias $base_root/api/web/;
try_files $uri /api/web/index.php$is_args$args;
location ~ ^/api/assets/.+\.php(/|$) {
deny all;
}
}
location ~ ^/.+\.php(/|$) {
rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;
fastcgi_param SCRIPT_FILENAME $request_filename;
if (!-f $request_filename) {
return 500;
}
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ /\. {
deny all;
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/admin/web/site.com/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/admin/web/site.com/stats/;
include /home/admin/conf/web/site.com.auth*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/snginx.site.com.conf*;
}
Но так не работает. Ошибка
[error] 26703#26703: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 185.183.15.19, server: site.com, request: "GET /api HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001"
Помогите разобраться.
P.S. Ответы "сделай разные поддомены" просьба не писать, так как основной сайт - это и есть поддомен
Ответы (1 шт):
Автор решения: Diefair
→ Ссылка
не знаю, почему так (с nginx начал работать недавно), но когда изменил название папки на restapi - заработало