This tutorial provides a comprehensive guide on deploying an Angular application on a Rocky Linux server using NGINX as a web server. Rocky Linux, a community enterprise operating system, is known for its stability and enterprise-level reliability, making it an excellent choice for hosting web applications. NGINX, renowned for its high performance and low resource consumption, serves as the perfect web server to deliver your Angular application efficiently.
By the end of this tutorial, you will learn how to set up your Rocky Linux environment, install the necessary software (Node.js, NPM, Angular CLI), create and build an Angular application, install and configure NGINX to serve your app, and manage firewall settings for secure and optimal web access.
This guide is intended for developers, system administrators, or anyone interested in deploying Angular applications. It assumes basic knowledge of Angular, Linux command line, and networking concepts.
Before you begin, ensure you have:
Deploying your Angular application on a Rocky Linux server with NGINX offers several benefits:
By following this guide, you’ll gain the skills and knowledge needed to successfully deploy and manage your Angular applications in a Linux server environment.
Let’s get started!
Update all packages:
sudo dnf update
Install Node.js and NPM, required for building Angular applications:
sudo dnf install nodejs npm
Install Angular CLI globally:
sudo npm install -g @angular/cli
Create and navigate to your Angular application:
ng new my-angular-appcd my-angular-app
Build your app for production:
ng build --configuration production
This creates a dist/
folder with your app.
Install and start NGINX:
sudo dnf install nginxsudo systemctl start nginxsudo systemctl enable nginx
Edit the NGINX configuration file:
cd /etc/nginxsudo nano nginx.conf
(or use sudo vi nginx.conf
)
Configure the server block (adjust the root path accordingly):
server {listen 80;server_name example.com;location / {root /path/to/your/dist/my-angular-app;index index.html index.htm;try_files $uri $uri/ /index.html;}}
Open HTTP (port 80) on the firewall:
sudo firewall-cmd --permanent --zone=public --add-service=httpsudo firewall-cmd --reload
Restart NGINX to apply the new configuration:
sudo systemctl restart nginx
Your Angular application should now be accessible via your server’s IP address or domain name.
For an app named “my-angular-app”:
server {listen 80;server_name myapp.example.com;location / {root /var/www/my-angular-app/dist/my-angular-app;index index.html index.htm;try_files $uri $uri/ /index.html;}}
Note: This guide provides the basic steps. For production environments, consider additional security measures and configurations.
Deploying an Angular application is just the beginning. The real journey involves continuous learning and improvement, adapting to new challenges, and leveraging the strengths of your tools and environment. Keep exploring, keep learning, and keep building amazing applications on robust platforms like Rocky Linux and NGINX.
For more information and resources about Angular and deploying it on Rocky Linux with NGINX, you can refer to the following links:
If you encounter any issues while following this tutorial, here are some common problems and their solutions:
root
directive in NGINX configuration correctly points to the dist/
directory of your Angular app.We value your feedback on this tutorial! If you have any questions or suggestions for improvement, please feel free to reach out:
We’re here to help with any queries or issues you might have and are eager to enhance your experience with deploying Angular on Rocky Linux and NGINX.
Quick Links
Legal Stuff