在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  Linux/ nginx 不能用同一個端口不同的域名去訪問嗎?為什么我的server_name

nginx 不能用同一個端口不同的域名去訪問嗎?為什么我的server_name不起作用

我本地有個nginx環(huán)境,但是我們有很多項(xiàng)目,都需要用80端口,但是,為什么我配置Nginx里面多個server里面都監(jiān)聽80端口,然后通過server_name去區(qū)分,在nginx配置里面建了多個.conf的文件,我發(fā)現(xiàn)每個域名(我在host里面設(shè)置的到80的域名),都會跳轉(zhuǎn)到我第一個項(xiàng)目上面


etc/hosts 代碼如下

127.0.0.1   dev.demo.com
127.0.0.1   dev.blog.com

nginx 配置文件路徑

圖片描述

第一個項(xiàng)目nginx配置

server {

    #listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;
    listen 80;

    server_name dev.blog.com;
    root /var/www/blog/public;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }
return 404;
}

第二個項(xiàng)目配置

server {

    #listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;
    listen 80;

    server_name dev.demo.com;
    root /var/www/demo;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }
}

問題是,我現(xiàn)在訪問 dev.blog.com是正常的,但是,訪問dev.demo.com,也會跳轉(zhuǎn)到blog的項(xiàng)目下面,而且,hosts里面,所有指向127.0.0.1的,都會訪問到blog項(xiàng)目,請問下,nginx不同像apache一樣,通過域名配置虛擬主機(jī)嗎?

回答
編輯回答
初心

感謝666666666666666666666

2017年5月29日 18:47
編輯回答
舊酒館

找到原因了,主要是我本地用了vpn,關(guān)了vpn就沒事了,神了

2017年10月3日 12:36