问答

nginx 域名配置的疑惑

作者:admin 2021-04-19 我要评论

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

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

问题:我有 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的项目

###

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

###

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

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • nginx响应速度很慢

    nginx响应速度很慢

  • 点击选中的多选框,会在已选那一栏显示

    点击选中的多选框,会在已选那一栏显示

  • PHP 多态的理解

    PHP 多态的理解

  • 关于C语言中static的问题

    关于C语言中static的问题

腾讯云代理商
海外云服务器