0

I'm trying to deploy my angular application on my EC2. I already have a Different app running on port 3000. now i'm trying to deploy my angular app on port 3030. but when i access it via the IP:3030 it works fine, but after configuring it with nginx it returns black page and with some 404 error on the Network tab.

server {
     listen 443 ssl;

     server_name <ABC.DOMAIN.COM>;

     ssl_certificate /etc/letsencrypt/live/<ABC.DOMAIN.COM>/fullchain.pem;
     ssl_certificate_key /etc/letsencrypt/live/<ABC.DOMAIN.COM>/privkey.pem;
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
     ssl_prefer_server_ciphers on;
     ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

     root /usr/share/nginx/html;
     index index.html index.htm;

     # Make site accessible from http://localhost/
     server_name localhost;

     location / {
         proxy_pass http://localhost:3000/;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto http;
         proxy_set_header X-Nginx-Proxy true;
         proxy_redirect off;
     }
      location /goalmate{
        rewrite /goalmate/(.*)$ /$1 break;
        proxy_pass http://localhost:3030/;
    }
}
 }

 server {
     listen 80;

     server_name <ABC.DOMAIN.COM>;

     return 301 https://$host$request_uri;
 }

Error Showing in the Networktab

can someone help me.? should'nt the requeston the networkTab show domain.com/goalmate/assets/ other than domain.com/assests

6
  • You should rebuild your angular app according to your URL prefix, check this Q/A. Commented Oct 12, 2020 at 17:54
  • And after that you shouldn't do any rewrites or change an URI with proxy_pass directive. Check this one Q/A too. Commented Oct 12, 2020 at 17:58
  • @IvanShatsky I'm using a express server to serve my Angular app on Port 3030, I still shouldn't use rewrite? Commented Oct 12, 2020 at 17:59
  • If you don't rebuild your app using /goalmate/ base href prefix, all the assets links would be generated as /some/path instead of /goalmate/some/path and therefore would be served by location / { ... } block leading to 404 errors. After rebuilding the app you wouldn't need any rewrites. Commented Oct 12, 2020 at 18:04
  • @IvanShatsky Thank You soo much mate! it worked.! i've a small doubt too! right now on my app, i'm calling the api like domain.com/api is there anyway fro me to call it like localhost:8086. i'e tried changing it to localhost, but then on my networktab all request goes to localhost:8086 not my api endpoint! Commented Oct 12, 2020 at 18:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.