1

使用vvv-nginx-custom.conf文件覆盖默认设置时,是否需要保持与默认相同的格式?它是否还需要包含默认值的所有内容?

我有点困惑,或者我误解了方向。

默认文件配置:

server {
    listen       80;
    listen       443 ssl http2;
    server_name  {vvv_hosts};
    root         {vvv_path_to_site}{vvv_public_dir};

    # Nginx logs
    error_log    {vvv_path_to_site}/log/nginx-error.log;
    access_log   {vvv_path_to_site}/log/nginx-access.log;

    # This is needed to set the PHP being used
    set          $upstream {upstream};

    # Enable server push if SSL/HTTP2 is being used for link preload headers
    http2_push_preload on;

    {vvv_tls_cert}
    {vvv_tls_key}

    # Nginx rules for WordPress, rewrite rules, permalinks, etc
    include      /etc/nginx/nginx-wp-common.conf;

    {{LIVE_URL}}

    location ~* \.(css|eot|gif|ico|jpeg|jpg|js|png|svg|tiff|tiff|ttf|webp|woff|woff2)$ {
        expires 100d;
    }
}

这是否意味着定制的需要看起来像这样?

server {
    listen       80;
    listen       443 ssl http2;
    server_name  {vvv_hosts};
    root         {vvv_path_to_site}{vvv_public_dir};

    # Nginx logs
    error_log    {vvv_path_to_site}/log/nginx-error.log;
    access_log   {vvv_path_to_site}/log/nginx-access.log;

    # This is needed to set the PHP being used
    set          $upstream {upstream};

    # Enable server push if SSL/HTTP2 is being used for link preload headers
    http2_push_preload on;

    {vvv_tls_cert}
    {vvv_tls_key}

    # Nginx rules for WordPress, rewrite rules, permalinks, etc
    include      /etc/nginx/nginx-wp-common.conf;

    {{LIVE_URL}}

    location ~* \.(css|eot|gif|ico|jpeg|jpg|js|png|svg|tiff|tiff|ttf|webp|woff|woff2)$ {
        expires 100d;
    }

    # Custom rules
    install_plugins: # Various way to install a plugin
     - query-monitor
     - classic-editor
     - wordpress-seo
     - all-in-one-wp-migration
     - timber-library
    wpconfig_constants:
        WP_DEBUG: true
        WP_DEBUG_LOG: true
        WP_DISABLE_FATAL_ERROR_HANDLER: true # To disable in WP 5.2 the FER mode
}
4

1 回答 1

1

严格来说,您不必包含所有内容,只是当您删除或更改某些内容时,它们会损坏。

如果您可以安全地删除或更改配置行,您可以在NGINX 文档中查找并得出结论。一个好的起点是nginx 如何处理请求

并阅读该配置中的评论。如果您不需要所描述的功能,您可以在不破坏内容的情况下将其删除。

或者只是改变一些东西,运行vagrant reload --provision并检查,如果一切正常。但我承认,这可能需要很长时间。

例如,如果您删除server_name,则默认为server_name "";,请参阅NGINX Docs for server。那么你可能没有找到正确的服务器,因为......

如果它的值不匹配任何服务器名称,或者请求根本不包含这个头域,那么 nginx 会将请求路由到这个端口的默认服务器。在上面的配置中,默认服务器是第一个——这是 nginx 的标准默认行为。
-- nginx如何处理请求

更改root会将请求发送到错误的文件夹...不要更改它。

如果需要,您可以毫无问题地删除日志。


这是 VVV 中 WordPress 网站的最小配置。你会丢失所有日志、HTTPS 和缓存,但它在技术上是有效的。

server {
    # Could be removed, because default is `listen *:80 | *:8000;`
    listen       80;
    server_name  {vvv_hosts};
    root         {vvv_path_to_site}/public_html;

    # This is needed to set the PHP being used
    set          $upstream {upstream};
    
    # Nginx rules for WordPress, rewrite rules, permalinks, etc
    include      /etc/nginx/nginx-wp-common.conf;

    {{LIVE_URL}}
}
于 2020-12-03T20:30:17.130 回答