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;
    server_name foobar.net www.foobar.net test.io www.test.io;

    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.

Cheers.

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.

×
1 answer

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.

  • Thank you @alexdo for your time and effort. Yesterday, late-night, I’ve solved my problem.
    Sure I had php-fpm installed because I had no problems without Nginx serving as a reverse proxy.
    It seems that the problem was this line:
    server_name foobar.net www.foobar.net test.io www.test.io;
    When I changed it to:
    server_name _;
    everything came back to normal.

    I don’t understand it since the former line had a correct syntax but there you are.

    Cheers.

Submit an Answer