目标:

目标:

目标:

从我的 VPS 为几个低流量域(主要是静态内容)提供服务。目前,我在 FreeBSD 下使用 Nginx。

问题:

我的include声明似乎被完全忽略了。即使我在包含的.conf文件中放入了胡言乱语,sudo nginx -t也表示一切都很好。因此,我的所有域名都提供相同的默认登录页面,实际上只有直接访问服务器的 IP 地址才能找到该页面。

如果我转到http://example.com/example.com/html/,就会出现我想要显示的页面http://example.com。我还可以转到 来http://www.example.com/domain2.com/html/查看 应该显示的内容http://domain2.com

我遗漏了什么可以让所有网站转到同一页面?

文件:

/usr/local/etc/nginx/nginx.conf

user  www;
worker_processes  1;

error_log /var/log/nginx/error.log info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    #Setup multiple domains
    server_names_hash_bucket_size 64;
    include /etc/nginx/sites-enabled/*.conf;

    #Default Server, for going straight to the IP address
    server {
        listen  80 default_server;
        listen [::]:80 default_server;
        listen  443 ssl default_server;
        listen [::]:443 ssl default_server;
        server_name _;

        #ssl on; #currently off for the bare IP
        #ssl_certificate        /etc/nginx/ssl/default.crt;
        #ssl_certificate_key    /etc/nginx/ssl/default.key;

        access_log  /var/nginx/log/access.log;
        root    /var/www/;
        index   index.php index.htm index.html;
   }

}

/usr/local/etc/nginx/sites-enabled/example.com.conf

(实际上是 的符号链接/usr/local/etc/nginx/sites-available/example.com.conf

server {
    listen       80;
    listen  [::]:80;
    listen       443 ssl;
    listen  [::]:443 ssl;
    server_name  example.com www.example.com;

    ssl on;
    ssl_certificate     /etc/letsencrypt/live/example.com/cert.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    root /var/www/example.com/html/;
    index index.php index.html index.htm;

    location = / {
            try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
    }

    #include /usr/local/etc/nginx/common.conf #for future use for common parts of the server block for all domains
}

答案1

包含路径:

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

以及文件:

/usr/local/etc/nginx/sites-enabled/example.com.conf

不同的目录


您可以使用以下内容包含相对于nginx配置目录的内容:

include sites-enabled/*.conf;

或者指定绝对位置如下:

include /usr/local/etc/nginx/sites-enabled/*.conf;

相关内容