php - NGiNX 配置为子文件夹上的 PHP 应用程序和 Angular 应用程序提供服务

标签 php angular linux nginx centos

我正在寻找一个配置示例来配置我的 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/

相关文章:

php - 如果数据存在则更新数据库

php - Symfony 2 : Find matching firewall, 基于路由名称

angular - 如何从 Intellij idea 2017.1 运行 Angular 应用程序?

linux - 为什么通配符在 if 子句 bash 中不起作用

linux - 找出以秒为单位的时间戳差异

linux - 使用 sed 替换/删除带重音的拉丁字符

php - 没有正则表达式的句子大小写

php - 非常基本的重写规则问题

angular - 如何判断 Angular 6 App 是否处于 Angular 项目之外的生产模式

javascript - Angular 2 : Cannot read property 'vcRef' of undefined