Nginx 设置了多个站点配置,这些配置会覆盖全局站点配置中的设置吗?

Nginx 设置了多个站点配置,这些配置会覆盖全局站点配置中的设置吗?

由于我是网络托管新手,我一直在使用一个名为迪特皮各种单板计算机。Dietpi 利用 Web 服务器的全局配置启用所有站点,如下面维护者所述。

我们为所有网站使用单一全局配置的主要原因是: - 对于大多数用户来说,这种全局网站配置是理想的,它允许用户简单地将网站“拖放”到 /var/www 中,而无需设置单独的网站配置。 - 我们必须支持 3 个 Web 服务器(Apache2、Nginx、Lighttpd)。从简化维护和支持的角度来看,我们更希望为每个 Web 服务器提供一个默认网站。

如果您希望通过多个站点配置来控制站点,这是可以的,但是在 dietpi-software 中再次安装任何软件都会重写(并启用)全局站点配置。

这种设置会导致一些问题,尤其是在 NextCloud 的示例中。

  1. 使用 Certbot 设置 SSL
  2. 为 webDav 重写 .well-known
  3. Nextcloud 有很多优化和安全性,这些都是其管理手册所推荐的,不应该放在全局配置中。

Dietpi的配置如下。

/etc/nginx/站点可用/默认

server {

    listen 80 default_server;

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

    server_name "$hostname";

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

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www;
    }

    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    include /etc/nginx/sites-dietpi/*.config;

}

/etc/nginx/nginx.conf

user www-data;

# As a thumb rule: One per CPU.
worker_processes 4;

# Maximum file descriptors that can be opened per process
# This should be > worker_connections
worker_rlimit_nofile 100;

events {
    worker_connections 50;
}

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

pid /run/nginx.pid;

http {

    charset utf-8;

    # + Nginx - To avoid 2MB upload error: https://github.com/Fourdee/DietPi/issues/546
    client_max_body_size 8796093022207M;

    # Upstream to abstract back-end connection(s) for PHP
    upstream php {
        server unix:/run/php5-fpm.sock;
    }

    # Set the mime-types via the mime.types external file
    include mime.types;

    # And the fallback mime-type
    default_type application/octet-stream;

    # Click tracking!
    access_log off;

    # Hide nginx version
    server_tokens off;

    # ~2 seconds is often enough for HTML/CSS, but connections in
    # Nginx are cheap, so generally it's safe to increase it
    keepalive_timeout 2;

    # You usually want to serve static files with Nginx
    sendfile on;

    tcp_nopush on; # off may be better for Comet/long-poll stuff
    tcp_nodelay off; # on may be better for Comet/long-poll stuff

    server_name_in_redirect off;
    server_names_hash_bucket_size 64;
    types_hash_max_size 2048;

    gzip off;
    gzip_http_version 1.0;
    gzip_comp_level 1;
    gzip_min_length 512;
    gzip_buffers 4 8k;
    gzip_proxied any;
    gzip_types
        # text/html is always compressed by HttpGzipModule
        text/css
        text/plain
        text/x-component
        application/javascript
        application/json
        application/xml
        application/xhtml+xml
        application/x-font-ttf
        application/x-font-opentype
        application/vnd.ms-fontobject
        image/svg+xml
        image/x-icon;

    # This should be turned on if you are going to have pre-compressed copies (.gz) of
    # static files available. If not it should be left off as it will cause extra I/O
    # for the check. It would be better to enable this in a location {} block for
    # a specific directory:
    # gzip_static on;

    gzip_disable "msie6";
    gzip_vary on;

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

我不能干扰“nginx.conf”和“默认”配置,否则会破坏 dietpi 软件的兼容性。是否可以使用多个站点配置来覆盖全局站点配置中的设置?

答案1

只需在里面添加虚拟主机配置/etc/nginx/sites-available并创建指向该文件的符号链接即可/etc/nginx/sites-enabled。这是基于 Debian 的发行版多年来采用的标准方法。

相关内容