Nginx config file for Nodejs and Vuejs
13:43 | 0 comments

Put this config file in /etc/nginx/sites-available/ and make a soft link for this file in /etc/nginx/sites-enabled/ directory . you can see the code in read more section .

server {
    server_name www.academi.rahasahamrah.com academi.rahasahamrah.com;

    location / {
    # vuejs dist folder 
     root /var/academy/public/dist;
     try_files $uri $uri/ /index.html;
    }

    location /api/ { 
   # proxy_pass /api/ for node server 
    proxy_pass http://185.94.99.69:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgarade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    client_max_body_size 100M;

    }

   location /upload {
    proxy_pass http://185.94.99.69:9000;
    proxy_http_version 1.1;
    proxy_set_header Upgarade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    client_max_body_size 150M;

    }

    location @rewrites {
    rewrite ^(.+)$ /index.html last;
   }


    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

   
    listen 443 http2 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/academi.rahasahamrah.com/fullchain.pem;
 
    ssl_certificate_key /etc/letsencrypt/live/academi.rahasahamrah.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}
server {
    if ($host = www.academi.rahasahamrah.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = academi.rahasahamrah.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen       80;
    server_name www.academi.rahasahamrah.com academi.rahasahamrah.com;
    return 404; # managed by Certbot


    ssl_dhparam /etc/ssl/certs/dhparam.pem;

}

COMMENTS

Post your comment

Your email address will not be published. Required fields are marked *