Report this

What is the reason for this report?

LAMP+ NGINX reverse proxy on CentOS

Posted on September 26, 2014

Hey guys. I am having lots of difficulty getting this to work.

My hope is to install Joomla, but with NginX driving the static content, and apache driving the php, on Cent OS.

I tried doing a LAMP install and then using Reverse proxy on Cent OS, but I cant seem to get it right.

Id love it if you guys had a walkthrough for this exact topic. Apache is still a very popular webserver, and having NginX infront of it would help a lot. I know it works, I just cant seem to do it myself because whenever I read online, depending which flavor of linux is used in a tutorial, some stuff ends up moving around, and wrapping my mind around this topic is a bit frustrating.



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.

There are a few tutorials that touch on this on the site, but they are mostly aimed at Ubuntu. Though it will be very similar. The main difference is the package names and the file location.

The first step is to set up Nginx to serve content as normal, but proxy all requests for php files to port 8080. Your Nginx config should look like:

server {
        listen   80; 

        root /var/www/; 
        index index.php index.html index.htm;

        server_name example.com; 

        location / {
            try_files $uri $uri/ /index.php;
        }

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

         location ~ /\.ht {
                deny all;
        }
}

Now you’ll need to set up Apache to listen on 127.0.0.1:8080 in /etc/httpd/conf/httpd.conf Find and change the any lines referencing port 80 and change them to 8080. In particular, this line:

Listen 80

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.