0

I am having slight issues making my indexes work with nginx serving static content and passing php to apache on a different server.

Basically if I need it to try index.php on the backend apache server when xxx.co.uk/ is requested. If no index.php or index.html exists on the nginx server i get 403 Forbidden. If i request xxx.co.uk/index.php behaviour is as expected and apache serves the page.

Could anyone suggest a solution to this? My initial thoughts was using try_files - but exactly how I am unsure - my tinkering didn't work!

I hope I have been clear, if not then please ask and I will try to elaborate further.

Nginx settings:

server
{
   listen 80;
   server_name www.xxx.co.uk xxx.co.uk;
   access_log /srv/www/xxx.co.uk/logs/access.log;
   error_log /srv/www/xxx.co.uk/logs/error.log;

   root /srv/www/xxx.co.uk/public_html;

   index index.php index.html;

   # deny access to apache .htaccess files
   location ~ /\.ht
   {
        deny all;
   }

   location ~* ^.*\.php$ {

        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.0.6:80;
    }   
}

and apache:

 <VirtualHost 192.168.0.6:80>
     ServerAdmin webmaster@xxx.co.uk
     ServerName xxx.co.uk
     ServerAlias xxx.co.uk www.xxx.co.uk
     DocumentRoot /srv/www/xxx.co.uk/public_html/
     ErrorLog /srv/www/xxx.co.uk/logs/error.log
     CustomLog /srv/www/xxx.co.uk/logs/access.log combined
     DirectoryIndex index.php
</VirtualHost>
  • I should also note if I place a blank index.php on the nginx server, it will work as required. The blank nginx index.php is ignored and the apache2 index.php is served. However this isn't ideal as I don't want to have to place blank 'dummy' files in every directory. – Chris B May 25 '13 at 18:59
0

You need a try_files and a location to put it in.

Example:

location / {
    try_files $uri $uri/ =404;
}
  • Not had chance to try yet, when I do I will feedback and accept if it works :) Thanks! – Chris B May 26 '13 at 17:08
  • Just tried this, got rid of the index line and used location / { try_files index.php index.html/ =404; } Instead of 403 I now get 404. Obviously it is trying the nginx server for index.php, how would I make it try the apache server/make it follow the proxy pass rule? – Chris B May 26 '13 at 17:22
  • Why did you get rid of the index line? That would certainly cause it to fail. – Michael Hampton May 26 '13 at 20:59
  • the outcome with or without appears to be the same - it still doesn't try the proxy server for the .php file. – Chris B May 26 '13 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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