By gremociones
Is it possible to run both PHP and Node.js application on the same server with Nginx? I use nginx as reverse proxy for node.js while on PHP I use nginx as substitute for Apache web server.
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!
Check this Gist… it works for me ;)
Practically you can copy and paste, just need to update the routes.
https://gist.github.com/yacafx/a730903e8ec69063c18394e4752b6657
Hope this works for you!
This is definitely possible. It can be implemented by setting up separate server blocks for each app. Check out this tutorial:
At its most basic, you can create a separate block for each. This uses the server_name directive to route requests to example.com to your php app and requests to node.example.com to the node app running on port 2368.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/php;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name node.example.com;
root /usr/share/nginx/html/node;
index index.html index.htm;
client_max_body_size 10G;
location / {
proxy_pass http://localhost:2368;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}
If you need to do something a little more complicate, you might also want to check out:
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.