nginx在ssl_certificatepath上使用$ server_name

如何在文件path中使用variables名?

ssl_certificate /home/ec2-user/.certificados/$server_name.crt; ssl_certificate_key /home/ec2-user/.certificados/$server_name.key; 

你不能在每个指令中使用variables。 ssl_certificate被视为一个文字string,是不支持variables的许多指令之一。

要为主机指定不同的证书,必须将其显式写入服务器块中:

 http { server_name example.com; ssl_certificate /home/ec2-user/.certificados/example.com.crt; ssl_certificate_key /home/ec2-user/.certificados/example.com.key; # ... } http { server_name example.net; ssl_certificate /home/ec2-user/.certificados/example.net.crt; ssl_certificate_key /home/ec2-user/.certificados/example.net.key; # ... } # ... 

如果您觉得不适合复制configuration,请使用这些模板创build模板并生成nginxconfiguration。 另见http://nginx.org/en/docs/faq/variables_in_config.html