Question

LAMP+ NGINX reverse proxy on CentOS

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.


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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