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

时间:2014-12-16 17:33:40

标签: node.js drupal nginx

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

例如:

proxy_pass http://127.0.0.1:2468;

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

像这样:

server_name example.com;

root /var/www/example;

当我转到指向我服务器的3个域时,它们都会显示Drupal站点。我无法理解为什么它会覆盖这些设置。这三个站点都有单独的config exampledomain.conf Nginx文件。

有没有人有任何想法?我已经尝试了好几天了!

DRUPAL SERVER 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;
    }
    }

SERVER 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;
    }
    }

SERVER 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;
    }
    }

1 个答案:

答案 0 :(得分:1)

给它一个机会。我发现了原始服务器块存在的一些问题,并对您要执行的操作做了一些假设。如果我弄错了,请告诉我。

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

您的原始服务器块出现了一些错误,例如我已经简化了使用www / non-www的多个块。请注意,如果您计划以非www方式处理www,则只需将这些块分成不同的块。

最后请注意,请确保使用“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;
    }
}