In a chef, the order of the commands in the recipe is the order of execution. if you saved templatefor nginx.confand it appeared after your command cookbook_file, the generated template will overwrite your file.
eg.
# cookbook file
cookbook_file "#{node[:nginx][:dir]}/nginx.conf" do
source "my_nginx.conf"
mode 0644
owner "root"
group "root"
end
# template
template "nginx.conf" do
path "#{node[:nginx][:dir]}/nginx.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode 0644
notifies :reload, "service[nginx]"
end
templatewill overwrite the file installed cookbook_file.