簡體   English   中英

nginx從本地主機重定向到http:// _ /

[英]nginx redirect from localhost to http://_/

我遇到一個奇怪的問題:當我從Nginx服務器內部,服務器命令行(通過ssh連接)或服務器外部(使用curl或wget)詢問此url時:

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的任何建議?

最后是一個網站重定向和$_SERVER變量的問題:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM