Report this

What is the reason for this report?

Configure Nginx as a Proxy for Apache

Posted on July 3, 2014

Hello,

I just recently setup my Nginx server config running Webmin, and Centos.

Since my setup is a fresh build. I’m wondering if I would theoretically just need to install Apache?

Where in the instructions would I find the proxy configuration?

https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-front-end-proxy-for-apache



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

and make the required config changes to my virtual host:

The root was set to the correct web directory index.php was added on the index line try_files attempts to serve whatever page the visitor requests. If nginx is unable, then the file is passed to the proxy proxy_pass lets nginx the address of the proxied server Finally the “location ~ /.ht {” location block denies access to .htaccess files, if Apache’s document root concurs with nginx’s one

The instructions in that tutorial proxy requests needing php on to Apachae. In this set up, Nginx is just used to serve static files.

The proxy part of you Nginx server block would look like:

       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:8080;
         }

Personally, I’d just set up Nginx to serve the PHP files as well using fpm unless I had a real need for Apache.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.