【问题标题】:NginX access configurationNginX 访问配置
【发布时间】:2013-05-06 07:52:38
【问题描述】:

我使用 ubuntu x64 服务器和 nginx 作为网络服务器。

在我公司,我们配置了 Intranet(本地)dns 服务器,这样当您输入 domain1.com 时,它会直接进入定义的 LAN ip 地址。

我们需要对位于同一台服务器上的 domain2.com 进行全局访问。当我们为 domain2.com 开启全局访问时,出现如下问题:

如您所知,任何人都可以检测到 domain2.com(我们的服务器)的 IP 地址。

问题是,当您直接使用服务器的全局 IP 地址访问时,服务器会自动打开 domain1.com,必须限制全局访问。这是 domain1.com 的 nginx 配置:

server
{
set $host_path "/var/www/domain1";

server_name domain1.com;

root $host_path;
set $yii_bootstrap "index.php";

client_max_body_size 2000M;
client_body_buffer_size 1024k;

listen       80;

    charset utf-8;
    index index.php index.html;

access_log  /var/access_log;
error_log /var/error_log;

location ~ /(protected|framework|nbproject) {
        deny all;
        access_log off;
        log_not_found off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;
        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }


}

如何使 domain1.com 只用于局域网(限制全局访问)?

【问题讨论】:

    标签: ubuntu web nginx ubuntu-12.04


    【解决方案1】:

    如果 nginx 正在处理一个缺少主机名的请求,并且没有一个虚拟服务器在其 listen 指令中具有 default_server 参数,它会使用它找到的第一个虚拟服务器。在您的情况下,它是 domain1.com。您应该做的是将 domain2.comlisten 指令更改为:

    listen 80 default_server;
    

    这样,当有人在没有主机名的情况下使用您的 IP 地址时,将为他们提供 domain2.com 内容。

    如果你想严格要求一个主机名并对没有指定它的请求返回 404,你可以创建一个新的 server 子句:

    server {
        listen 80 default_server;
        return 404;
    }
    

    还有另一种可能的解决方案:如果我理解正确,您的服务器有两个 IP:内部和外部。如果这是真的,您可以将 domain1.com 配置的listen 指令更改为listen 10.1.0.1:80;,其中10.1.0.1 是您的内部IP 地址。这样 domain1.com 将只能从您的 LAN 访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      • 2017-10-30
      • 2012-03-17
      • 2012-08-17
      • 1970-01-01
      相关资源
      最近更新 更多