nginx从localhost重定向到http:// _ /

时间:2016-02-22 01:46:00

标签: nginx wget

我遇到一个奇怪的问题:当我从我的nginx服务器内部,服务器命令行(通过ssh连接)或服务器外部询问此URL时,使用curl或wget:

ubuntu@test.myserver.com: $ wget https://test.myserver.com/print/document/view/1729 --no-check-certificate

我收到了这个回复:

--2016-02-22 01:28:49--  https://test.myserver.com/print/document/view/1729
Resolviendo test.myserver.com (test.myserver.com)... 1.2.3.4
Conectando con test.myserver.com (test.myserver.com)[1.2.3.4]:443... conectado.
AVISO: no se puede verificar el certificado de test.myserver.com, emitido por “emailAddress=info@test.myserver.com,CN=test.myserver.com,OU=Test,O=Test,L=Test,ST=Test,C=ES”:
  Se encontró un certificado autofirmado.
    AVISO: el nombre común “myserver.com” del certificado no encaja con el nombre de equipo “test.myserver.com” solicitado.
Petición HTTP enviada, esperando respuesta... 302 Moved Temporarily
Ubicación: http://_/print/document/view/1729 [siguiente]
--2016-02-22 01:28:49--  http://_/print/document/view/1729
Resolviendo _ (_)... falló: Nombre o servicio desconocido.
wget: no se pudo resolver la dirección del equipo “_”

但是当我的计算机(外部服务器)从Firefox请求时https://test.myserver.com/print/document/view/1729正常工作并获得响应代码200(任何地方都没有302重定向)。当Chrome要求时,错误是相同的。这是我的nginx配置:

server {
    listen 80 default_server;
    listen 443 default_server ssl;

    server_name _;
    root /var/www/drupal;

    ssl_certificate /etc/nginx/ssl/certificate.crt;
    ssl_certificate_key /etc/nginx/ssl/certificate.key;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

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

    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 / {
        # try_files $uri @rewrite; # For Drupal <= 6
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    # In Drupal 8, we must also match new paths where the '.php' appears in the middle,
    # such as update.php/selection. The rule we use is strict, and only allows this pattern
    # with the update.php front controller.  This allows legacy path aliases in the form of
    # blog/index.php/legacy-path to continue to route to Drupal nodes. If you do not have
    # any paths like that, then you might prefer to use a laxer rule, such as:
    #   location ~ \.php(/|$) {
    # The laxer rule will continue to work if Drupal uses this new URL pattern with front
    # controllers other than update.php in a future release.
    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    location ~* ^((?!system).)*\.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}

我需要能够从服务器本身访问公共IP,因为phantomjs正在使用它从url生成pdf。

有关如何配置nginx的任何建议吗?

1 个答案:

答案 0 :(得分:0)

最后是网站重定向和$_SERVER变量的问题:

$_SERVER['SERVER_NAME'] == '_';                 // as configured in nginx.conf
$_SERVER['HTTP_HOST']   == 'test.myserver.com'; // extracted from request