我有一个 React 前端和一个 Symfony 后端,我试图在同一个域上提供服务。 React 前端需要提供资产(如果存在),否则需要提供回退服务index.html
.
我想在以下情况下提供 php Symfony 应用程序/api
位于请求 uri 中。与 React 应用程序类似,我需要将所有请求发送到index.php
file.
前端服务正常,但 api 服务不正确。当我点击时,我从 nginx 收到 404/api
在浏览器中。
我觉得我很接近,但由于某种原因 nginx 没有正确的$document_root
。我正在添加一个标题(X-script
)来测试变量是什么,我得到以下结果:
X-script: /usr/share/nginx/html/index.php
这是我的 nginx 配置。
server {
listen 80 default_server;
index index.html index.htm;
access_log /var/log/nginx/my-site.com.log;
error_log /var/log/nginx/my-site.com-error.log error;
charset utf-8;
location /api {
root /var/www/my-site.com/backend;
try_files $uri $uri/ /index.php$is_args$args;
}
location / {
root /var/www/my-site.com/frontend;
try_files $uri /index.html;
}
location ~* \.php$ {
add_header X-script "$document_root$fastcgi_script_name" always;
try_files $fastcgi_script_name =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
任何帮助将非常感激。
Symfony 4 项目的 Web 根目录必须包含public
子文件夹。我没有使用 NGINX,但我认为这是正确的配置:
location /api {
root /var/www/my-site.com/backend/public;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)