1

I have a setup where my nginx is in front with apache+PHP behind.

My PHP application cache some page in memcache which are accessed by nginx directly except some dynamic part which are build using SSI in Nginx.

The first problem I had was nginx didnt try to use memcache for ssi URI.

<!--# include virtual="/myuser" -->

So I figured that if I force it to use a full URL, it would do it.

<!--# include virtual="http://www.example.com/myuser" -->

But in logs file (both nginx and apache) I can see that a slash has been added at the beginning of the url

http ssi filter "/http://www.example.com/myuser"

In the source code of the SSI module I see a PREFIX that seems to be added, but I can really tell if I can disable it.

Anybody got this issue? Nginx version : 0.7.62 on Ubuntu Karmic 64bits

Thanks a lot

stunti
  • 855
  • 8
  • 20

2 Answers2

20

You can configure nginx to include remote URLs despite you cannot refer them directly in SSI instructions. In site config create location with local path and named remote location that points where you want to. For example:

server {
....
  location /remote {
    proxy_pass @long_haul; # or use "try_files" to provide fallback
  }

  location @long_haul {
    proxy_pass http://porno.com;
  }
....
}

and in served html use include directive that refers /remote path:

  <!--# include virtual="/remote/rest-of-url&and=parameters" -->

Note that you may customize URL that is passed further with variables and regexp. For example:

  location ~/remote(.+) {
    proxy_pass @long_haul$1?$args;
  }
Petr Gladkikh
  • 1,906
  • 2
  • 18
  • 31
  • That's pretty awesome. You can use that in combination w/ a specialized log to do really simple outbound link service with analytics. – Anatoly G Jun 17 '12 at 21:38
  • But you should remember that whole round-trip to remote page will go via your nginx. That is nginx should hold some state awaiting while remote URL is fetched. Therefore I would not suggest such method for heavily loaded sites (just consider what happens if remote URL would take long time to load). – Petr Gladkikh Jun 21 '12 at 06:50
2

It has nothing about nginx, you just can't do that. SSI doesn't accept remote uri. you can only specify a local file path.

See http://en.wikipedia.org/wiki/Server_Side_Includes