By jamesbedont
I have installed the LEMP stack with this guide and have installed wordpress with this guide. They were both great guides but I need help making a small change.
I want for the root route to reverse proxy into a Node.js server. I would then like the /blog route to serve the wordpress site. As it stands right now the root route servers the wordpress site perfectly.
/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name my_ip;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
How would I modify this Nginx config so that /blog is wordpress and all other routes are handled by a Node.js 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!
Accepted Answer
Start by creating your /blog
directory and move your data over. Then you’d need to change:
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
to
location /blog {
try_files $uri $uri/ /index.php$is_args$args;
}
For the /
location block, we need to setup proxy_pass
to point to the location of your Node app.
location / {
proxy_pass http://APP_PRIVATE_IP_ADDRESS:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Where http://APP_PRIVATE_IP_ADDRESS:8080
points to your Node App. So for example, if your app is running on:
127.0.0.1:2365
You’d use:
http://127.0.0.1:2365
You’d then want to reload NGINX:
systemctl reload nginx
or
service nginx restart
Hi James,
Check out this post and linked answer. Hope it helps. StackOverflow solution
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!
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.