So let's start with a default Nginx as a front end proxy for Apache configuration:
Code: Select all
server {
listen 8080;
server_name www.example.com;
access_log /var/log/nginx/www.example.com-access.log;
error_log /var/log/nginx/www.example.com-error.log;
root /home/web;
index index.php index.html index.htm;
# Attempt to serve pages
location / {
try_files $uri $uri/ /index.php;
}
# Pass php pages on to Apache
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:80;
}
# Deny acces to Apache's .htaccess files
location ~ /\.ht {
deny all;
}
}
The above config will let Nginx serve all the static files under /home/web and pass everything else on to Apache, including requests for files that don't exist as far as Nginx is concerned. This means that because /admin is not in /home/web, Apache will be serving the static files in this location and the CGI is doing the PHP files. Inserting the next bit to the Nginx config file fixes this:
Code: Select all
# Serve static files from web-admin, rewrite virtual files for processing by CGI
location /admin/ {
root /usr/share/web-admin;
try_files $uri /admin/index.php?/$uri;
}
# Pass dynamic pages from web-admin on to the CGI
location ^~ /admin/index.php {
root /usr/share/web-admin;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/lib/apache2/fastcgi/fcgi;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
That's it. You can now stop Apache and verify that you can still access the admin pages. Alternatively you can monitor the logs with `tail -f` to verify that no requests for /admin are passed on to Apache.