Nginx: Angular pages not being loaded

Asked

Viewed 106 times

0

I have a backend application Node.js (Adonis) and frontend (angular). I installed Nginx and set it up this way:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    server {
        listen 80;

        server_name meudominio.com ;

        location / {
            proxy_pass http://localhost:3333;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_cache_bypass $http_upgrade;
        }
    }


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

When I start the Nginx service and navigate to my browser page, it is shown as if I were performing a get on my api, instead of showing the angular dist files that are on public_html

How to make Nginx work both my backend and my frontend? Currently with this setting only backend works.

I tried to add root and index configuration in Location and server:

root /home/nomeservidor/public_html
index index.html index.htm

But there was no difference.

In my CPANEL, in Omains, I configured the public_html folder as root, but it doesn’t seem to work.

In conjunction with Nginx I am using pm2, I tried to restart but also failed.

  • 1

    Two servers being set to the same port will give conflict.

1 answer

1

 location /api-checkmilk-nest/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://xx**`texto em negrito`**.us-west-2.elb.amazonaws.com/;
            }

            location /agrotrace/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://xx.us-west-2.elb.amazonaws.com/;
            }

            location /rest-project/{
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://xx:8079/rest-project/;
            }

            location /api-checkmilk-v3/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://xx.us-west-2.elb.amazonaws.com/;
            }

            location /api-biodiesel-v3/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://xx.us-west-2.elb.amazonaws.com/;
            }

This is an excerpt of a configuration that I use inside the block of port 443, taking into account that the links of AWS for example I expose the front or back already on the corresponding ports for example api:3000 responds at 80 of the link of AWS I hope you can help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.