多个IP地址上的Nginx单域

时间:2013-12-03 10:44:21

标签: apache nginx plesk

我正在使用Plesk 11,其中nginx位于Apache前面,侦听端口80和443,并使用proxy_pass将请求重定向到Apache侦听端口7080和7081。

我正在更新从1.2.3.46.7.8.9的DNS记录,并希望在切换期间有两个IP地址的网站。

如何启用该功能?

这是我尝试过的,但它不起作用(Plesk提供了默认的“此域尚未配置”页面):

# Nginx
server {
    # listen 6.7.8.9:80;
    listen 80;
    server_name example.com;
    server_name www.example.com;

    client_max_body_size 128m;

    root "/var/www/vhosts/example.com/httpdocs";
    access_log /var/www/vhosts/system/example.com/logs/proxy_access_log;

    location / {
        proxy_pass http://6.7.8.9:7080;
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
        access_log off;
    }

    location /internal-nginx-static-location/ {
        alias /var/www/vhosts/example.com/httpdocs/;
        add_header X-Powered-By PleskLin;
        internal;
    }
}


# Apache - setup to listen on new IP address
<VirtualHost 6.7.8.9:7080 >
    ServerName "example.com:80"
    ServerAlias  "www.example.com"
    UseCanonicalName Off

    <IfModule mod_suexec.c>
        SuexecUserGroup "example" "psacln"
    </IfModule>

    ServerAdmin  "jon@example.com"

    DocumentRoot "/var/www/vhosts/example.com/httpdocs"
    CustomLog /var/www/vhosts/system/example.com/logs/access_log plesklog
    ErrorLog  "/var/www/vhosts/system/example.com/logs/error_log"

    <IfModule mod_ssl.c>
        SSLEngine off
    </IfModule>

    SetEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/example.com/etc/php.ini
    SetEnv PP_CUSTOM_PHP_CGI_INDEX module

    <IfModule mod_fcgid.c>
        FcgidInitialEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/example.com/etc/php.ini
        FcgidInitialEnv PP_CUSTOM_PHP_CGI_INDEX module
        FcgidMaxRequestLen 134217728
    </IfModule>

    <Directory /var/www/vhosts/example.com/httpdocs>

        <IfModule sapi_apache2.c>
        php_admin_flag engine on

        # General settings
        php_admin_flag safe_mode off
        php_admin_value open_basedir "/var/www/vhosts/example.com/:/tmp/"
        # Performance settings
        # Additional directives
        </IfModule>

        <IfModule mod_php5.c>
        php_admin_flag engine on

        # General settings
        php_admin_flag safe_mode off
        php_admin_value open_basedir "/var/www/vhosts/example.com/:/tmp/"
        # Performance settings
        # Additional directives
        </IfModule>

        Options -Includes -ExecCGI
    </Directory>

1 个答案:

答案 0 :(得分:0)

您可以通过在虚拟主机模板中添加丑陋的黑客来实现:

首先创建自定义模板:

mkdir -p /usr/local/psa/admin/conf/templates/custom/domain/

cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
cp /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.php

如果进行以下更改,我只针对SSL部分进行了更改:

domainVirtualHost.php中的更改:

<VirtualHost <?php echo $OPT['ipAddress']->escapedAddress ?>:<?php echo $OPT['ssl'] ? $VAR->server->webserver->httpsPort : $VAR->server->webserver->httpPort ?> <?php echo ($VAR->server->webserver->proxyActive && $OPT['ipAddress']->isIpV6()) ? "127.0.0.1:" . ($OPT['ssl'] ? $VAR->server->webserver->httpsPort : $VAR->server->webserver->httpPort) : '' ; ?> <?php echo ($VAR->domain->asciiName == 'special.tld') ? ' 1.2.3.4:' . $VAR->server->webserver->httpsPort : '' ?>>

添加nginxDomainVirtualHost.php:

<?php if ($VAR->domain->asciiName == 'special.tld' ): ?>
    listen 1.2.3.4:443 ssl;
<?php   endif ?>

在/ usr / local / psa / admin / bin / httpdmng之后--reconfigure-domain special.tld

你得到以下配置(或面板中的错误,某些虚拟主机无法重新配置):

head /var/www/vhosts/system/special.tld/conf/last_httpd.conf

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.
#IF YOU REQUIRE TO APPLY CUSTOM MODIFICATIONS, PERFORM THEM IN THE FOLLOWING FILES:
#/var/www/vhosts/system/special.tld/conf/vhost.conf
#/var/www/vhosts/system/special.tld/conf/vhost_ssl.conf
<IfModule mod_ssl.c>

<VirtualHost 6.7.8.9:7081   1.2.3.4:7081>


head /var/www/vhosts/system/special.tld/conf/last_nginx.conf

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.



server {
    listen 6.7.8.9:443 ssl;
    listen 1.2.3.4:443 ssl;