Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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!
I’ve just finished setting up a droplet using your: https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-6 (which I copy/pasted my way through without issue).
I have just ran through this guide too on setting up a virtual host. When I tried to access a .php file though, the browser tried to download the content. I assumed the .php config in the /etc/nginx/conf.d/default.conf would have handled it. Instead for my virtual host I am using:
server { listen 80; server_name www.example.com example.com; root /var/www/example.com/public_html/; index index.php index.html index.htm;
try_files $uri /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The try_files is to push all non-file requests - example.com/some/path/some/var - to the index.php file for typical MVC framework.
If the browser tried to download the PHP file that means that you do not have an interpreter running.
Please make sure that you ran:
Or as root:
This will then run php-fpm which is what nginx will proxy to, to process php scripts.
I tried these configurations, very nice and working all these up to 6th step. but when i tried for virtual hosting, it doesn’t working, I gave them entry in /etc/hosts as ip nginx.com and I changed thier root directories… Why is this no working? Please help
i’ve try the virtual hosts server blocks and it’s success. but when i try to adding more website/multiple site on the virtual.conf, i only get succes for the first site. other site cannot rearch server. i have dig the website and it’s success only for the first site. below is my virtual.conf
server { listen 80;
server_name mfaridlutfi.com;
location / {
root /var/www/mfaridlutfi.com/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/mfaridlutfi.com/public_html/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mfaridlutfi.com/public_html/;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/mfaridlutfi.com/public_html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
server { listen 80;
server_name designev.com;
location / {
root /var/www/designev.com/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
}
server { listen 80;
server_name smartphonereviewers.com;
location / {
root /var/www/smartphonereviewers.com/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
}
the mfaridlutfi.com is success loading, the designev.com and smartphonereviewers cannot reach the server. any help ? thanks
@M. Farid lutfi: The websites are loading fine for me. It could be DNS propagation that took a long time.
In case of virtual hosting, the server_name directive must contain both example.com and www.example.com if any of them are omitted then nginx will redirect the missing url request to the default server_name. Example: server { … … server_name defaultwebsite.com … … } server { … … server_name example.com; … … } In this case if you request for www.example.com then nginx will redirect you to the default server name ie defaultwebsite.com It doesn’t matter even if you setup the CNAME record for www.example.com to example.com
The correct form must be server_name example.com www.example.com
This tutorial is currently not working! I tried this and when i go on to my website. It just downloads the index.php file? Any help???
@Harsh: This article doesn’t configure nginx to work with php. Do you have php-fpm installed?
Install it if you do not and add this block to your nginx virtualhost config: <a href=“https://p.kk7.me/rowumehile.nginx”>https://p.kk7.me/rowumehile.nginx</a>
Same problem here, I do everything in this tutorial on the droplet I created but it just do the download instead of processing php file. I try service php-fpm restart and it is reports okay but still no success.