9

Does nginx offer a way to add the hostname (and port) in an HTML file (without using other solutions, such as PHP)?

1 Answer 1

13

May be SSI is what you are looking for?

All variables, which available in core module also available in ssi module.

Usage example:

<!--# echo var="host" default="unknown_host" -->:<!--# echo var="server_port" default="unknown_port" --> 

I had put this string inside test.html and invoke this page through http://localhost/test.html

As a result I get following string:

localhost:80

Sign up to request clarification or add additional context in comments.

4 Comments

I'd like to retrieve it automatically, maybe a nginx-provided variable I can drop in. I could resort to get it from a hardcoded HTML file if there's no other way, but I'm curious to see if there's some other option.
Well, something like the $date_local or $date_gmt variables offered by SSI, but with hostname and port
I've updated my answer, you can find example of usage SSI module
Don't forget to add ssi on; to nginx.conf

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.