Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Angular Universal in Apache

I have been encountering problem regarding deployment of Angular ssr on Apache.

I believe, configuration on apache is needed alongwith .htaccess file. Below are some links which I have been through, but either I was not able to configure or the description was not thorough enough to implement.

https://github.com/angular/universal-starter/issues/514

Angular2 Universal deploy to apache remote server

How to properly launch Angular Universal to live server

How to deploy Angular Universal project to standard hosting?

My issue is deploying Angular Universal on Apache server with port configured to 8080 and inside a directory 'custom' -- x.x.x.x:8080/custom

Steps Taken

1) Deployed dist/* to /var/www/html/custom

2) npm install to install deps

3) pm2 to start server.js under dist folder

Screen shot attached-- enter image description here

enter image description here

enter image description here

Navigating to x.x.x.x:8080/custom gives the directory structure instead.

I think I need to redirect requests to the port that the app started with PM2 is listening on.

How shall that be done is my concern

Help much appreciated !!


1 Answers

We are using pm2 ecosystem to point localhost

First enable mod_proxy and mod_proxy_http in httpd.conf!

If you are using virtual host add the following proxy setting to your domain-specific host file-

ProxyPreserveHost On
ProxyPass / http://localhost:4200/
ProxyPassReverse / http://localhost:4200/

Restart your Apache and pm2

So if you accessing your live domain e.g www.example.com will serve by pm2 through localhost:4200

like image 163
Priyesh Avatar answered Jan 22 '26 18:01

Priyesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!