nginx server中的server_name配置的域名在客戶機上無法訪問


nginx配置如下:

nginx.conf:

#user  nobody;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


    server {
        listen       80;
        server_name  server8.test.com;
        root /var/www/web1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

          location / {
        index index.html index.htm;
    }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

   server {
    listen 80 default_server;
    server_name  www8.test.com;
        root /var/www/web2;
    index index.html index.htm;
    access_log /var/log/nginx/www.gmq.com-access.log main;
    error_log /var/log/nginx/www.gmq.com-error.log warn;
    }
    
}

1、server_name配置的隨便寫的域名,客戶機無法訪問問題?

如上,這是我服務器配置的nginx的配置文件,我在客戶機上面,怎么訪問都不行。郁悶!

解決:

網上很多說設置hosts文件,對,確實是這樣解決的,但是沒說是設置客戶機還是服務器的hosts文件!!坑

我自己解決:

因為是我局域網的,我設置客戶機的訪問hosts文件,這才正確,日了狗了!!!

如下:

在客戶機上設置hosts文件:

增加以下兩句話,即可,服務器上的hosts文件不需要設置:

(服務器IP  域名)

192.168.100.189       server8.gmq.com
192.168.100.189       www8.gmq.com

以上解決!!!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM