D
D
Deeno2019-12-10 11:22:13
Apache HTTP Server
Deeno, 2019-12-10 11:22:13

How to run Angular SSR on a server?

Hello everyone, I have compiled an application on Angular Universal, how can I upload it to the server and run it in order to get access via a direct link and not using the port that is specified in the server.js file (i.e. site.com: 4000)
Maybe you need to configure the server for the correct display, I checked what the isBrowserPlatform function returns, at startup it returns the browser, and in theory it should return the server
Nowhere could I find any tutorials on how to deploy this case
Server on Apache, I use pm2 to run it
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Art, 2020-01-05
@Deeno

Since Apache is listening on ports 80 and 443, you have only 2 options:
1. Add the mod_proxy module to Apache and proxy requests to port 4000 through it
2. Finally go to the 2-level server and use nginx as a proxy. For nginx I use this config

server {
  server_name m.example.ru ;
  ssl_certificate "/var/www/httpd-cert/example/m.example.ru_le1.crtca";
  ssl_certificate_key "/var/www/httpd-cert/example/m.example.ru_le1.key";
  ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
  ssl_prefer_server_ciphers on;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  add_header Strict-Transport-Security "max-age=31536000;";
  ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
  charset off;
  index index.php index.html;
  disable_symlinks if_not_owner from=$root_path;
  set $root_path /var/www/example/data/angular/mobile/src;
  root $root_path;
  gzip on;
  gzip_comp_level 9;
  gzip_disable "msie6";
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
  location / {
    location ~ [^/]\.ph(p\d*|tml)$ {
      try_files /does_not_exists @fallback;
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      expires max;
      try_files $uri $uri/ @fallback;
    }
    location / {
      try_files /does_not_exists @fallback;
    }
  }
  location @fallback {
    proxy_pass http://127.0.0.1:4000;
    proxy_redirect http://127.0.0.1:4000 /;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port $server_port;
    access_log off;
  }
  access_log off;
  error_log /var/www/httpd-logs/m.example.ru.error.log notice;
  listen 80.252.130.250:443 ssl http2;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question