How I can use a variable name in file path ?

ssl_certificate /home/ec2-user/.certificados/$server_name.crt;
ssl_certificate_key /home/ec2-user/.certificados/$server_name.key;
  • Claythinho, if an answer solves your problem you can mark your question as "solved" by clicking the "accept button" on the left of an answer. If you cannot find it, have a look at meta.serverfault.com/q/1033/51929 – Lekensteyn May 10 '13 at 21:31
up vote 29 down vote accepted

You cannot use variables in every directive. ssl_certificate is treated as a literal string and is one of the many directives where variables are unsupported.

To specify different certificates for hosts, you have to explicitly write it in a server block:

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;
    # ...
}
# ...

If you feel uncomfortable duplicating the configuration, create templates and generate the nginx configuration using those templates. See also http://nginx.org/en/docs/faq/variables_in_config.html.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.