Reputation: 170658
I want to use the same config nginx site config file for test and change only the servername and port.
How can I achieve that or something close to it?
I want something like: if hostname==xxx listen on 80 else listen on 81.
Upvotes: 0
Views: 542
Reputation: 3236
You could put all the shared parts in a separate file (say, common.conf
) and include that in two minimalistic server
blocks, like this:
http {
[...]
server {
listen 80;
server_name production.local;
root /some/path/production;
include common.conf;
}
server {
listen 81;
server_name testing.local;
root /some/path/testing;
include common.conf;
}
}
Edit
Actually, you don't even need the listen
directives. They default to listen 80
when running as root, and to listen 8000
otherwise. As long as you have a DNS entry, or hosts file entry, you'd be good.
Upvotes: 2