I have a Django with Nginx configuration which is working fine, here is my configuration:
- server {
- listen 80;
- server_name my.hiddendomain.com;
-
- location / {
- proxy_pass http://127.0.0.1:8000;
- 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 /static/ {
- alias /path/to/your/static/files/;
- }
-
- location /media/ {
- alias /path/to/your/media/files/;
- }
- }
I need to add a custom php script on the same domain however it’s not working. For testing purposes, I’ve created a <?php phpinfo();
file but it’s not working.
In the config file I’ve shown above I’ve added
location /custom-php {
alias /var/www/html/info.php
}
When I attempt to open the file, the url loads however I get a pop-up asking me where to download the file.
How to resolve this please?
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.
Hello,
It seems like you don’t have PHP installed on your Droplet and your system doesn’t know what to do with the .php file and it just lets you download it. Additionally, to have Nginx serve your PHP file properly, you need to have a PHP processor like PHP-FPM (FastCGI Process Manager) installed and configured to work with Nginx. Here’s how you can set it up:
For Ubuntu/Debian:
For CentOS/RHEL:
For Ubuntu/Debian:
For CentOS/RHEL:
Now, when you visit
my.hiddendomain.com/custom-php
, it should display the PHP file as a webpage. Note that if you’re using a different version of PHP, you’ll need to adjust the version numbers in the paths accordingly.