Connected Tutorial(This question is a follow-up to this tutorial):
How To Configure Nginx as a Web Server and Reverse Proxy for Apache on One Ubuntu 20.04 ServerHello, I installed NGINX as a reverse proxy for my Apache and when I’m trying to access the web, It starts downloading the index.php file (with no name). I have completely same files as in this tutorial. (Only domain changed). I need help with this.
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!
Hi there @ondrejnovy,
This usually happens due to misconfigured PHP-FPM settings.
Does this also happen if you try to access the Apache service directly on port 8080? For example if you create an info.php file and then access http://your_server_ip:8080/info.php do you get the content PHP info page?
Can you share your Apache Vhost config and the /etc/apache2/mods-enabled/fastcgi.conf file here?
Another thing that I could suggest is also checking your Apache error log:
- tail -100 /var/log/apache2/error.log
Also, do you have a .htaccess file inside your document root? If so I could suggest temporary disabling it to test if it is causing the issue for you.
Regards, Bobby
When PHP files are downloaded instead of being executed by the server, it usually indicates an issue with the configuration of the server that’s supposed to process PHP files—in your case, Apache, which is behind NGINX as a reverse proxy. Here’s a step-by-step guide to troubleshoot and fix the issue:
First, ensure that NGINX is correctly configured to pass PHP requests to Apache. Here’s a typical configuration example where NGINX acts as a reverse proxy:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8080; # Ensure Apache listens on this port
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;
}
location ~ \.php$ {
proxy_pass http://127.0.0.1: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;
}
}
This configuration assumes that Apache is listening on port 8080. Make sure your Apache server is configured to listen on the port specified in the proxy_pass directive.
Next, verify that Apache is set up to handle PHP files correctly. Ensure that the mod_php module is enabled and correctly configured:
mod_php is enabled:sudo a2enmod php8.x # Replace "8.x" with your PHP version
<VirtualHost *:8080>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options +FollowSymLinks
AllowOverride All
Require all granted
AddType application/x-httpd-php .php
</Directory>
DirectoryIndex index.php index.html
</VirtualHost>
The AddType directive should not be necessary when using mod_php, but it’s good to check everything related to PHP handling.
3. ** Don’t Forget to restart both Nginx and Apache**
Verify that PHP is installed and configured correctly. You can check your PHP installation by creating a info.php file in your document root with the following content:
<?php phpinfo(); ?>
Try accessing http://yourdomain.com/info.php from your browser. If PHP is configured correctly, this should display the PHP information page.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.