Best way to protect changes to nginx.conf from "bench setup nginx"

Hi Team, All,

Could you please let me know the best way to make sure that changes made to nginx.conf in the bench folder are not lost when I run bench setup nginx ?

My scenario is that I have a couple of subdomains *.host.com that I’m redirecting to host.com using the following block

server{
	listen 80;
	server_name	*.host.com;
	return 301	http://host.com$request_uri;
}

I would not like this to be overwritten when next I run bench setup nginx.

Regards,
cksgb

3 Likes

Add a new file in /etc/nginx/conf.d for your other directives

1 Like

Thanks. Got it.

Regards,
cksgb

Why not have ERPNext approach nginx.conf the way WordPress security plugins approach .htaccess, simply appending their changes to the file instead of replacing it?

Hey, I know this is old but I want to achieve exactly the same. can you give steps on doing this solution?

what file name should I give to the new file in conf.d folder? I already have frappe-bench.conf file in it.
more importantly, how should I link this to nginx.conf in bench folder? should I write include /etc/nginx/conf.d/new_file in nginx.conf?

other than this what do I need to write in the file? :

server{
	listen 80;
	server_name	*.host.com;
	return 301	http://host.com$request_uri;
}

I used this technique and https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04 to make .php files co-exist with ERPNext

I had a need to allow php based applications run on the same server with nginx running ERPNext

Hope it helps others.