首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有多个子目录应用程序的Nginx服务器

具有多个子目录应用程序的Nginx服务器
EN

Server Fault用户
提问于 2022-11-02 09:40:38
回答 2查看 388关注 0票数 1

我的团队有一个用于内部工具和测试的服务器。它有一个指向它的子域:myserver.mycompany.com。我们试图实现的是拥有多个应用程序,每个应用程序都在一个子目录下。即:

  • myserver.mycompany.com -泛型条目页
  • myserver.mycompany.com/redmine我们的内部红宝石( rails服务器上的红宝石)
  • myserver.mycompany.com/opensocial,我们目前正在测试的一个drupal网站(一个php应用程序)

我设法让redmine在子目录下工作,而不是在子目录上的drupal网站上工作。

有什么建议吗?

下面是我的默认vhost的简化版本:

代码语言:javascript
复制
server {
    
    # server name and ssl stuff

    root /var/www/html;

    ## REDMINE
    location ~ ^/redmine(/.*|$) {
            alias /opt/redmine/public$1;
            passenger_base_uri /redmine;
            passenger_app_root /opt/redmine;
            passenger_document_root /opt/redmine/public;
            passenger_enabled on;
    }
    ## END REDMINE


    ## START Open Social
    location ~ ^/opensocial(/.*|$) {

            alias /var/www/opensocial/html$1;
            index index.php;

            location ~ ^/opensocial(/.*|$) {
                    try_files $uri /index.php?$query_string; # For Drupal >= 7
            }

            # From nginx's drupal config
            location ~ '\.php$|^/update.php' {
                    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
                    # Ensure the php file exists. Mitigates CVE-2019-11043
                    try_files $fastcgi_script_name =404;
                    # Security note: If you're running a version of PHP older than the
                    # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
                    # See http://serverfault.com/q/627903/94922 for details.
                    include fastcgi_params;
                    # Block httpoxy attacks. See https://httpoxy.org/.
                    fastcgi_param HTTP_PROXY "";
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_param PATH_INFO $fastcgi_path_info;
                    fastcgi_param QUERY_STRING $query_string;
                    fastcgi_intercept_errors on;
                    # PHP 7 socket location.
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            }

    }
    ## END OF Open Social

谢谢

EN

回答 2

Server Fault用户

发布于 2022-11-02 14:23:37

这主要是评论(但注释框中的空间有限)

我设法让redmine在子目录下工作,但没有在drupal网站上工作。

当您尝试访问drupal时,What发生在浏览器上?你的日志上写了什么?

代码语言:javascript
复制
location ~ ^/opensocial(/.*|$) {
            alias /var/www/opensocial/html$1;

这太可怕了。我猜您真的很想独立地管理这两个应用程序的路径。有什么很好的理由让你不用

代码语言:javascript
复制
location /opensocial {

当您使用类似的模式来处理红矿时,您确实在不同的位置安装了它。我并不熟悉乘客是如何工作的,但我认为passenger_base_uri会使正则表达式和别名变得多余。

就我个人而言,我会使用3个单独的服务器{}实例,并在端口80 & 443上放置一个代理--额外跳的开销可以忽略不计,并且有扩展、安全和管理的好处。

票数 0
EN

Server Fault用户

发布于 2022-11-04 11:03:13

基于@symcbean答案,我为每个应用程序创建了一个代理服务器。

我现在的问题是来自drupal网站的内部链接和资源上的404,但我想这是一个应用程序问题。

这是我的新主持人:

代码语言:javascript
复制
server {

        # server name and ssl stuff

        root /var/www/html;

        location /redmine {
                proxy_pass http://127.0.0.1:8000;
        }

        location /opensocial {
                proxy_pass http://127.0.0.1:8001;
        }

}

## REDMINE
server {
        listen 127.0.0.1:8000;
        root /opt/redmine/public;
        passenger_base_uri /redmine;
        passenger_app_root /opt/redmine;
        passenger_document_root /opt/redmine/public;
        passenger_enabled on;
}


## OPEN SOCIAL
server {
        listen 127.0.0.1:8001;
        root /var/www/opensocial/html;

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

        location ~ '\.php$|^/update.php' {
                fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
                # Ensure the php file exists. Mitigates CVE-2019-11043
                try_files $fastcgi_script_name =404;
                # Security note: If you're running a version of PHP older than the
                # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
                # See http://serverfault.com/q/627903/94922 for details.
                include fastcgi_params;
                # Block httpoxy attacks. See https://httpoxy.org/.
                fastcgi_param HTTP_PROXY "";
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param QUERY_STRING $query_string;
                fastcgi_intercept_errors on;
                # PHP 7 socket location.
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }


}

如果你有什么我能做得更好的事,请评论。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1114613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档