Node.js 应用程序和 Drupal Nginx 冲突

标签 node.js drupal nginx

我目前在我的 VPS 上运行两个 Ghost Node.js 博客。当我在各自的 .conf 文件中使用 proxy_pass 时,它们工作正常。

例如:

proxy_pass http://127.0.0.1:2468;

我在端口 2368 上有另一个博客。但是当我在我的 VPS 上引入 Drupal 站点时,我认为它可以正常工作,因为我的 .conf 设置文件正在读取路径和 URL。

像这样:

服务器名称 example.com;

root/var/www/example;

发生的情况是,当我访问指向我的服务器的 3 个域时,它们都显示 Drupal 站点。我不明白为什么它会覆盖设置。所有三个站点都有单独的配置 exampledomain.conf Nginx 文件。

有人有什么想法吗?我这几天一直在努力解决这个问题!

DRUPAL 服务器 block 1

    server {
    server_name leafylane.com;
    root /var/www/leafylane; ## <-- Your only path reference.
    # Enable compression, this will help if you have for instance advagg‎ module
    # by serving Gzip versions of the files.
    gzip_static on;
    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }
    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }
    # This matters if you use drush prior to 5.x
    # After 5.x backups are stored outside the Drupal install.
    #location = /backup {
    #        deny all;
    #}
    # Very rarely should these ever be accessed outside of your lan
    location ~* \.(txt|log)$ {
            allow 192.168.0.0/16;
            deny all;
    }
    location ~ \..*/.*\.php$ {
            return 403;
    }
    # No no for private
    location ~ ^/sites/.*/private/ {
            return 403;
    }
    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
            return 403;
    }
    location / {
            # This is cool because no php is touched for static content
            try_files $uri @rewrite;
    }
    location @rewrite {
            # You have 2 options here
            # For D7 and above:
            # Clean URLs are handled in drupal_environment_initialize().
            rewrite ^ /index.php;
            # For Drupal 6 and bwlow:
            # Some modules enforce no slash (/) at the end of the URL
            # Else this rewrite block wouldn't be needed (GlobalRedirect)
            #rewrite ^/(.*)$ /index.php?q=$1;
    }
    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_intercept_errors on;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    # Fighting with Styles? This little gem is amazing.
    # This is for D6
    #location ~ ^/sites/.*/files/imagecache/ {
    # This is for D7 and D8
    location ~ ^/sites/.*/files/styles/ {
            try_files $uri @rewrite;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }
    }

服务器 block 2

    server {
    listen 0.0.0.0:8080;
    server_name tomcusack.com;
    access_log /var/log/nginx/tomcusack.com.log;
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:2368;
    proxy_redirect off;
    }
    }
    server {
    listen 0.0.0.0:8080;
    server_name www.tomcusack.com;
    access_log /var/log/nginx/tomcusack.com.log;
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:2368;
    proxy_redirect off;
    }
    }

服务器 block 3

    server {
    listen 0.0.0.0:8080;
    server_name sancho-panza.co.uk;
    access_log /var/log/nginx/sancho-panza.co.uk.log;
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:2468;
    proxy_redirect off;
    }
    }
    server {
    listen 0.0.0.0:8080;
    server_name www.sancho-panza.co.uk;
    access_log /var/log/nginx/sancho-panza.co.uk.log;
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:2468;
    proxy_redirect off;
    }
    }

最佳答案

试一试。我发现了您的原始服务器 block 存在很多问题,并对您想要做什么做了一些假设。如果我弄错了,请告诉我。

您有一个 Drupal 安装和两个 Ghost 博客。您希望根据请求的 URL 在 VPS 计算机的端口 80 上提供所有这些服务。每个都需要接受 www 和非 www 请求。

您原来的服务器 block 有一些错误,例如对 www/非 www 使用多个 block ,我已对此进行了简化。请注意,如果您计划以与非 www 不同的方式处理 www,则只需将它们分成不同的 block 。

最后一点,请确保使用“sudo nginx -s reload”重新加载配置文件,因为如果有任何语法错误,这会输出更详细的调试信息

server  {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        server_name leafylane.com www.leafylane.com;
        root /var/www/leafylane; 
        gzip_static on;
        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
        location ~* \.(txt|log)$ {
                allow 192.168.0.0/16;
                deny all;
        }
        location ~ \..*/.*\.php$ {
                return 403;
        }
        location ~ ^/sites/.*/private/ {
                return 403;
        }
        location ~ (^|/)\. {
                return 403;
        }
        location / {
                try_files $uri @rewrite;
        }
        location @rewrite {
                rewrite ^ /index.php;
        }
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                fastcgi_intercept_errors on;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}

server {
    listen 80;
    server_name tomcusack.com www.tomcusack.com;
    access_log /var/log/nginx/tomcusack.com.log;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }

} 

server {
    listen 80;
    server_name sancho-panza.co.uk www.sancho-panza.co.uk;
    access_log /var/log/nginx/sancho-panza.co.uk.log;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:2468;
        proxy_redirect off;
    }
}

关于Node.js 应用程序和 Drupal Nginx 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27510542/

相关文章:

javascript - 在将每个对象作为一个类的 NodeJS 游戏中,应该如何处理事件?

node.js - 是否可以等到ask方法返回响应

php - 如何在 Drupal 8 中设置 session 变量并在 php 脚本中获取它?

php - 找不到命令 cim。 Drush 无法查询数据库

node.js - NodeJS 应该是独立的吗(即没有 apache nginx)

javascript - 如何从由 no-js 类组成的网页中转储表格数据?

php - db_affected_rows() 始终返回 false

mysql - Rails应用程序MYSQL错误nginx

javascript - BuzzFeed 如何进行移动重定向?

javascript - AWS S3 对象列表