2017-08-27 72 views
0

我在centos 7上安裝了nginx。我有一個問題。Nginx的任何子域重定向到「歡迎頁面默認」

當我去mydomain.com時,它會轉到我的項目製作。但是當我去任何子域
例如:anysubdomain.mydomain.com,它將我重定向到nginx的「歡迎頁面默認值」。
我該如何讓anysubdomain找不到(ERR_NAME_NOT_RESOLVED)。在

我的nginx的配置在/ etc/nginx的/網站,供laravel 5

server { 
    listen 80; 

    #webroot 
    root /var/www/myfolder/public; 
    index index.php index.html index.htm; 
    server_name mydomain.com; 
    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
    } 
    location ~ \.php$ { 
     try_files $uri = 404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/run/php-fpm/php-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

我的默認配置nginx的在/etc/nginx/nginx.conf

user nginx; 
worker_processes auto; 
error_log /var/log/nginx/error.log; 
pid /run/nginx.pid; 

# Load dynamic modules. See /usr/share/nginx/README.dynamic. 
include /usr/share/nginx/modules/*.conf; 

events { 
    worker_connections 1024; 
} 

http { 
    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; 
    tcp_nodelay   on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

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

    # Load modular configuration files from the /etc/nginx/conf.d directory. 
    # See http://nginx.org/en/docs/ngx_core_module.html#include 
    # for more information. 
    include /etc/nginx/conf.d/*.conf; 

    server { 
     listen  80 default_server; 
     listen  [::]:80 default_server; 
     server_name _; 
     root   /usr/share/nginx/html; 

     # Load configuration files for the default server block. 
     include /etc/nginx/default.d/*.conf; 

     location/{ 
     } 

     error_page 404 /404.html; 
      location = /40x.html { 
     } 

     error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
     } 
    } 

# Settings for a TLS enabled server. 
# 
# server { 
#  listen  443 ssl http2 default_server; 
#  listen  [::]:443 ssl http2 default_server; 
#  server_name _; 
#  root   /usr/share/nginx/html; 
# 
#  ssl_certificate "/etc/pki/nginx/server.crt"; 
#  ssl_certificate_key "/etc/pki/nginx/private/server.key"; 
#  ssl_session_cache shared:SSL:1m; 
#  ssl_session_timeout 10m; 
#  ssl_ciphers HIGH:!aNULL:!MD5; 
#  ssl_prefer_server_ciphers on; 
# 
#  # Load configuration files for the default server block. 
#  include /etc/nginx/default.d/*.conf; 
# 
#  location/{ 
#  } 
# 
#  error_page 404 /404.html; 
#   location = /40x.html { 
#  } 
# 
#  error_page 500 502 503 504 /50x.html; 
#   location = /50x.html { 
#  } 
# } 

#include 
include /etc/nginx/sites-enabled/*.conf; 
} 
+0

在'/ etc/nginx/default.d /'或'include/etc/nginx/sites-enabled'中會有'default.conf'。你需要擺脫那個conf –

+0

哦。是啊!謝謝!我禁用並且工作。 –

回答

1

會有一個/etc/nginx/default.d/中的default.conf或包含/ etc/nginx/sites-enabled。你需要擺脫那個conf。

當您使用子域時,正在激活該配置。

相關問題