Configure Nginx for MERN GraphQL app on Digitalocean

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference
Search for a command to run...

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference
No comments yet. Be the first to comment.
Add it to the boot method of the AppServiceProvider of the app to improve Laravel developmet experience. use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; class AppServiceProvider extends ServiceProvider { //... pub...

There is a plugin available for reactjs that one can use to add Calendly to Nextjs i.e., react-calendly. The problem is if you want to customize the button to open popup or modal then you need to have Calendly's pro plan for it. Here is the alternati...

After shifting to Ubuntu from Windows, I constantly look up for the alternatives of the tools that are available in Windows to enhance my arsenal in Linux. DbGate is the smartest SQL+noSQL database client. It works on Windows, Linux, MacOS and in web...

<div className="ratio ratio-16x9"> <video width="900" height="650" muted playsInline autoPlay loop> <source src="/images/test.mp4" type="video/mp4" /> </video> </div>

Creating middleware in Laravel is a common task that helps to filter HTTP requests entering your application. Middleware can perform various tasks such as authentication, logging, and modifying request/response objects. Step 1: Create Middleware You ...

You can configure Nginx for your MERN GraphQL app on the Digitalocean droplet and redirect www to the non-www domain over SSL. Copy and paste the following code in /etc/nginx/sites-available/domain.com.conf and then create a symbolic link to enable the new server block with the following command:
$ sudo ln -s /etc/nginx/sites-available/domain.com.conf /etc/nginx/sites-enabled/
server {
listen 443 ssl http2;
#Path to the React front end
root /var/www/html/domain.com;
#the main html file
index index.html;
#Enter the domain name
server_name domain.com;
#STORE the nginx access logs for this app here
access_log /var/log/nginx/domain.com.access.log;
#Store the error logs for this app here
error_log /var/log/nginx/domain.com.error.log;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
# Without this line routing in your Single Page APP will not work
try_files $uri $uri/ /index.html =404;
}
#GRAPHQL BACKEND CONFIG
location /api/ {
proxy_pass https://localhost:6443/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
# redirect all https traffic from www to non-www
server {
listen 443 ssl;
server_name www.domain.com;
return 301 https://domain.com$request_uri;
#change this to your certificate paths
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
}
# redirect all traffic from http to https
server {
listen 80;
server_name domain.com www.domain.com;
return 301 https://$host$request_uri;
}