我正在寻找一个配置示例来配置我的 CentOS 服务器以在同一域上运行 PHP 和 Angular 应用程序。 PHP 到目前为止运行良好,两个应用程序都将在常规用户(非 root)帐户下运行。
我的 PHP 根应用程序位于
public_html/
我的 Angular 应用程序位于
public_html/app
任何帮助将不胜感激。
最佳答案
人们劫持了这个问题,他们没有提供答案,而是提示没有提供示例代码。我最终自己找到了解决方案,因此我想分享它,以防有人面临同样的问题:
在我的具体情况下,我有 PHP 和纯 HTML(Angular)文件在不同的文件夹中,但在同一用户/域下。默认配置对于 PHP 文件可以正常工作,但是当我访问运行 Angular 8 应用程序的文件夹 /app
时,我收到了 502 错误。为了解决这个问题,我将以下内容添加到默认配置文件中:
location /app/ {
root /home/YOURUSER/public_html/app/;
try_files $uri $uri/ /index.html /index.htm /index;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
#Angular seems to have issues if you are not specific about CSS and JS files in headers
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
现在看来可以正常工作了。
关于php - NGiNX 配置为子文件夹上的 PHP 应用程序和 Angular 应用程序提供服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59041864/