【发布时间】:2022-01-10 23:37:50
【问题描述】:
我正在尝试进行 Nginx 配置,我可以在同一域上同时拥有 Angular 和 Symfony,但在 suburl 上拥有 Symfony。
问题是我一直收到 Symfony 配置的 404 Not Found。
我的网站有一个默认的登录重定向,我被重定向到 url,但是在我得到 404 之后。(test.com/api/connect/azure) 是我被重定向到的 URL .
2022/01/10 15:16:15 [错误] 23#23: *3 open() “/var/www/angular/back/public/connect/azure”失败(2:没有这样的文件 或目录)
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/test_com.pem;
ssl_certificate_key /etc/nginx/ssl/test_com.pem.com.key;
server_name test.com;
root /var/www/angular/front/dist;
location /api {
alias /var/www/angular/back/public;
index index.php
try_files $uri /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass php8:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_intercept_errors on;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $request_filename;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
}
location / {
try_files $uri $uri/ /index.html;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
【问题讨论】:
-
您的主要错误是
try_files最后一个参数被视为新的 URI,所以它应该是try_files $uri /api/index.php$is_args$args;。此外,还有一个长期存在的bug 将alias和try_files指令一起使用。您确定在/api/前缀下应该有任何静态非 PHP 文件吗?也许/api/...的所有请求都应该由index.php处理?或者有几个 PHP 脚本应该在/api/前缀下可用? -
是的,/api/ 的所有请求都应该由 Index.php 处理它们不是其他 PHP 脚本,除了应该调用的 Index.php 我添加了 try_files $uri /api/index.php $is_args$args;但我仍然有同样的问题
标签: php angular symfony nginx configuration