2017-08-30 151 views
0

我在www.example.com工作時遇到問題。網站在example.com上加載,但不在www.example.com上加載。我現在的配置文件/etc/nginx/sites-available/example.comNginx沒有提供www.example.com,但提供example.com

server { 
    listen 80; 
    server_name www.example.com; 
    return 301 http://example.com$request_uri; 
} 

server { 
    listen 80; 
    server_name example.com; 
    root /path/to/dir; 
    index index_en.html index.html; 
} 

我試圖與配置不同的方法,但沒有奏效。我還刪除了example.com塊,並且只爲www.example.com使用了一個,但www.example.com不起作用,但example.com仍然有效。當然,我在每次更改後都重新啓動了nginx。

我有DNS記錄兩者example.com和www.example.com,A和指向同一個IP。我也曾嘗試CNAME - 一個到另一個,等了幾個小時,什麼都沒有。還是一樣。現在我變得非常生氣了,因爲有了其他子域名,一切都運行良好,只是沒有www。

,是的,如果我搜索www.example.com在Firefox在Ubuntu 14.04,我得到找不到服務器。

# /etc/nginx/nginx.conf 

user www-data; 
worker_processes 4; 
pid /run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 

    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 
    # server_tokens off; 

    # server_names_hash_bucket_size 64; 
    # server_name_in_redirect off; 

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

    ## 
    # Logging Settings 
    ## 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    ## 
    # Gzip Settings 
    ## 

    gzip on; 
    gzip_disable "msie6"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # nginx-naxsi config 
    ## 
    # Uncomment it if you installed nginx-naxsi 
    ## 

    #include /etc/nginx/naxsi_core.rules; 

    ## 
    # nginx-passenger config 
    ## 
    # Uncomment it if you installed nginx-passenger 
    ## 

    #passenger_root /usr; 
    #passenger_ruby /usr/bin/ruby; 

    ## 
    # Virtual Host Configs 
    ## 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

我離開了郵件部分,因爲它被完全註釋掉了。

+0

需要一些調試信息。 '主機www.example.com','主機example.com'看到兩者都給予相同的IP或不。接下來發布您的配置nginx配置,而不僅僅是它的一部分 –

+0

我意識到DNS服務中必須有一個問題,因爲一切工作都很完美。是的,我嘗試了'host www.example.com'並且沒有輸出,這意味着它沒有被註冊,儘管我昨天註冊了它並且允許更改生效的最長時間是4個小時...將不得不打電話給他們我猜。 – campovski

+0

請確保您有您的DNS區域中的'@'項,這是爲根域 –

回答

0

它可能不得不與LAN和本地DNS緩存出現了一些本地的DNS設置做的,因爲我能夠從其他網絡訪問該網站。