【问题标题】:Nginx any subdomain redirect to "welcome page default"Nginx 任何子域重定向到“欢迎页面默认”
【发布时间】:2018-02-04 16:26:54
【问题描述】:

我在 centos 7 上安装了 nginx。但我遇到了问题。

当我访问 mydomain.com 时,它会进入我的项目生产。但是当我去任何子域时
例如:anysubdomain.mydomain.com,它将我重定向到 nginx 的“欢迎页面默认值”。
如何使找不到任何子域(ERR_NAME_NOT_RESOLVED)。

我在 /etc/nginx/sites-available for laravel 5 中的配置 nginx

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;
    }
}

我在 /etc/nginx/nginx.conf 中的默认配置 nginx

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;
}

【问题讨论】:

  • /etc/nginx/default.d/include /etc/nginx/sites-enabled 中会有一个default.conf。你需要摆脱那个conf
  • 哦。是的!谢谢!我禁用了它,它可以工作。

标签: php nginx dns


【解决方案1】:

/etc/nginx/default.d/ 中会有一个 default.conf 或包含 /etc/nginx/sites-enabled。你需要摆脱那种迷惑。

当您使用子域时,该配置被激活。

【讨论】:

    猜你喜欢
    • 2012-08-02
    • 2014-09-03
    • 2021-11-25
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2011-09-22
    • 2017-03-21
    相关资源
    最近更新 更多