How to check nginx config but without copying of new config file into nginx directory?

I have deployment script that copies include new nginx config file. I need to check nginx config by using nginx -t before deploying new application version.

Is it possible to check nginx config of particular file like?:

/usr/nginx/sbin/nginx -t -c /var/www/application/vhost.conf

Solution 1:

you could save a backup copy of the config, then edit/replace it, then issue nginx -s reload after the editing/replacing is done. if the config is invalid, nginx won't apply the changes, will report the exact place that he is unhappy about, and in the same time will keep using old valid one.

Solution 2:

You can test a particular file indeed but this file needs to be the main configuration that includes others and of course include paths must be adapted if you are shipping virtual hosts in separate files.

As a consequence, it's not possible to check a particular vhost configuration directly but it makes sense because server blocks are only parts of the main configuration.

/usr/nginx/sbin/nginx -t -c /path/to/nginx.conf