【问题标题】:how to configure multiple yii application over a single ip in nginx?如何在 nginx 中通过单个 ip 配置多个 yii 应用程序?
【发布时间】:2020-08-27 11:27:32
【问题描述】:

在我的情况下,有两个 yii2 应用程序并希望以这样的方式进行配置,以便我可以访问两个应用程序,如下所示。

app 1 frontend - somedomain.com/app1/
app 1 backend -  somedomain.com/app1/admin

app 2 frontend - somedomain.com/app2/
app 2 backend -  somedomain.com/app2/admin

我尝试过的。

我已经创建了 5 个 nginx 配置文件defualt.conf, app1-frontend.conf, app1-backend.conf, app2-frontend.conf, app2-backend.conf

defualt.conf

server {
    listen      80;
    server_name somedomain.com;

    location /app1 {
        proxy_pass  http://localhost:3000;
    }

    location /app1/admin {
        proxy_pass  https://localhost:3001;
    }

    location /app2 {
        proxy_pass  http://localhost:5000;
    }

    location /app2/admin {
        proxy_pass  https://localhost:5001;
    }
}

app1-frontend.conf

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 3000;
    server_name  127.0.0.1 localhost;

    root /home/dev/Desktop/app1/frontend/web;

    access_log  /home/dev/Desktop/app1/vagrant/nginx/log/frontend-access.log;
    error_log   /home/dev/Desktop/app1/vagrant/nginx/log/frontend-error.log;

    location / {
        index  index.html index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;
    }

    location ~ \.php {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        try_files $uri =404;
    }

    # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}

对于像app1-backend.conf, app2-frontend.conf, app2-backend.conf 这样的其他配置,除了端口和文档根目录外,一切都相同。

当我访问 http://somedomain.com/app1/ 时,我只得到了 html 页面,而在其他应用程序路线中得到了 404,而对于 http://somedomain.com/app1/admin,我得到了 502 错误。

有人知道怎么解决吗?

【问题讨论】:

    标签: php nginx deployment yii2


    【解决方案1】:

    您应该在 Google 上搜索的内容称为 SSO(单唱)。如果您使用 3rd 方身份验证提供程序(如 OAuth),您可以实现所需的行为 - 我得到了这样的环境。使用 JWT(JSON 湿令牌)和 Auth0 启动并运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-09
      • 2016-04-22
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 2021-01-30
      相关资源
      最近更新 更多