WordPress custom vvv conf format

98 views Asked by At

When using the vvv-nginx-custom.conf file to override the default settings, do you need to keep the same format as default? Does it need to include everything default has as well?

I'm a little confused or maybe I misunderstood the directions.

Default file configuration:

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

Does this mean the customized one would need to look like this?

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

There are 1 answers

0
Josef Wittmann On

Stricly speaking, you don't have to include everything, just some things will break, when you remove or alter them.

You can look things up in the NGINX documentation and conclude, if you can safely remove or alter the config line. A good starting point would be How nginx processes a request.

And read the comments in that config. If you don't need the described feature, you could remove it without breaking stuff.

Or just alter stuff, run vagrant reload --provision and inspect, if everything's working. But I admit, this could take ages.

For example, if you remove server_name, it defaults to server_name "";, see NGINX Docs for server. Then you might not hit the right server, because ...

If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour.
-- How nginx processes a request

Changing root will sent requests to the wrong folder... Don't change it.

You could remove the logs without problem, if you want.


This is a minimal config for a WordPress site in VVV. You lose all log, HTTPS and caching, but it technically works.

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