简体   繁体   English

nginx从本地主机重定向到http:// _ /

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

I'm having a strange issue: when I'm asking this url from inside my nginx server, in server command line (connection via ssh) or from outside the server, with curl or wget: 我遇到一个奇怪的问题:当我从Nginx服务器内部,服务器命令行(通过ssh连接)或服务器外部(使用curl或wget)询问此url时:

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

I'm getting this response: 我得到这个回应:

--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 “_”

But when requested from Firefox in my computer (outside server) https://test.myserver.com/print/document/view/1729 works fine and getting response code 200 (no 302 redirect anywhere). 但是,当从我的计算机(外部服务器)中的Firefox请求时, https://test.myserver.com/print/document/view/1729可以正常工作并获得响应代码200(没有302重定向到任何地方)。 When requested with Chrome the error is the same. 当使用Chrome请求时,错误相同。 Here it is my nginx config: 这是我的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;
    }
}

I need to be able to access to public ip from server itself because it's being used by phantomjs to generate pdf from url. 我需要能够从服务器本身访问公共IP,因为phantomjs正在使用它从URL生成pdf。

Any suggestion on how to configure nginx? 关于如何配置nginx的任何建议?

At the end was a question of website redirection and $_SERVER variables: 最后是一个网站重定向和$_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