大网数据广告活动
服务器运维问答

Nginx include directive having no effect

· 52CE 我爱测

Goal: Serve several low-traffic domains (mostly of static content) from my VPS. Currently, I'm using Nginx under FreeBSD. Problem: My include statement seemingly is entirely ignored. Even if I put gibberish in an included .conf f…

问题原文

原帖链接 · cjm · CC BY-SA 3.0

Goal:

Serve several low-traffic domains (mostly of static content) from my VPS. Currently, I'm using Nginx under FreeBSD.

Problem:

My include statement seemingly is entirely ignored. Even if I put gibberish in an included .conf file, sudo nginx -t says everything is all good. All of my domains therefore serve the same default landing page, which really should only be found if you go straight to the server's IP address.

If I go to http://example.com/example.com/html/, the page I want to be shown at http://example.com appears. I can also go to http://www.example.com/domain2.com/html/ to view what should be at http://domain2.com.

What am I missing that makes all sites go to the same page?

Files:

/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

(really a symlink for /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
}

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

The include path:

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

And the file:

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

are in different directories.


You can include relative to the nginx configuration directory with:

include sites-enabled/*.conf;

Or specify the absolute location as:

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。