Apache not parsing PHP behind Nginx reverse proxy

I’m trying to build an Ubuntu 18.04 based, Apache PHP-FPM web server with multiple virtual hosts, behind Nginx as a reverse proxy. Everything works fine up to the point where I configure Nginx to be the reverse proxy. Now I have this:

  • static HTML files are OK

  • php files are downloaded instead of executed

  • the worst thing is that when I try to fetch my info.php (which only has the basic HTML5 scaffold with title meta tag, to know which virtual host is served, and <?php phpinfo(); ?>) I’m being served with the different file, without a clue from where it was served.

When bypassing Nginx on port 8080 everything is back to normal and my PHP is working.

Here’s my /etc/nginx/sites-available/apache (my_server_ip is real IP):

server {
    listen 80;

    location / {
        proxy_pass http://my_server_ip:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

I’ve lost two days so far, I found no similar issues on the web, and I’m desperate so any help would be greatly appreciated.


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.

Hello, @WebshapedBiz

May I ask if you use or have installed php-fpm as well? The thing is that you will need it in order to serve those requests.

Looking forward to your reply.