nginx 域名配置的疑惑

user_xP0U4yVp
  • 16

问题:我有 a.comb.com两个域名,这两个域名都解析绑定的同一个ip,
但是服务器的nginx配置没有配置b.com,只配置了a.com,这时候 浏览器访问b.com却能指向a.com的nginx配置

nginx.conf 文件配置详情

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d目录下的a.com.conf

limit_req_zone $binary_remote_addr zone=req_one:32m rate=100r/s;
server {
    listen       80;
    listen       443 ssl;
    server_name  a.com;
    root  /home/wwwroot/a.com/public;

    ssl_certificate      /home/wwwroot/ssl/a.com.pem;
    ssl_certificate_key  /home/wwwroot/ssl/a.com.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    index index.html index.htm index.php;
        charset utf-8;
    
    location /ws {
                proxy_pass http://172.17.0.1:9004;
                # 转发websocket需要的设置
                proxy_set_header X-Real_IP $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X_Forward_For $proxy_add_x_forwarded_for;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
        }

        location / {
        limit_req zone=req_one burst=5 nodelay;
            try_files $uri $uri/ /index.php?$query_string;
        }
    location ~ \.php$ {
        fastcgi_pass   172.17.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_intercept_errors on;
        include        fastcgi_params;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ {
    try_files $uri /index.php;
        expires      30d;
    }

    location ~ .*\.(js|css)$ {
        try_files $uri /index.php;
        expires      12h;
    }
}

为什么只配置了a.com。浏览器访问b.com能指向a.com的项目

回复
阅读 612
2 个回答
✓ 已被采纳

这不是正常吗?你没有配置b.com。。我现在把我的域名解析到baidu的ip,同样也能访问baidu啊。baidu也没有对我的域名进行配置。。懂?尝试配置一下,不通过ip访问。。

Nginx 没有配置 default_server 的情况下,默认就是会匹配到第一个域名

你知道吗?

宣传栏