You can directly edit the default Nginx configuration file located in the `/etc/nginx/nginx.conf` or the `/etc/nginx/conf.d/` directory. Here's how you can set up your Angular application using the default configuration:
1. Build your Angular application:
Ensure you have built your Angular application using the `ng build --prod` command in your Angular project directory. This will generate the production-ready build in the `dist/` folder.
2. Install Nginx (if not already installed):
If Nginx is not installed, you can install it using your system's package manager. For example, on Ubuntu, you can run:
3. Configure Nginx to serve your Angular application:
Edit the default Nginx configuration file:
```bash
sudo nano /etc/nginx/nginx.conf
```
or
```bash
sudo nano /etc/nginx/conf.d/my-angular-app.conf
```
Replace `my-angular-app.conf` with an appropriate name for your application configuration file.
4. Update the Nginx configuration to serve your Angular app:
Add or modify the `server` block in the Nginx configuration to serve your Angular application:
```nginx
server {
listen 80;
server_name your_domain.com; # Change this to your actual domain or server IP
root /path/to/your/angular/app/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
```
Replace `your_domain.com` with your actual domain name or server IP address, and update `/path/to/your/angular/app/dist` to the path where your Angular application's `dist/` directory is located.
5. Restart Nginx to apply the changes:
```bash
sudo service nginx restart
```
6. Open your Angular application in a web browser:
With Nginx configured and your Angular application built and served, you should now be able to access your application using the domain name or IP address you specified in the Nginx configuration.
For example, if you used `your_domain.com` in the configuration, you can open your web browser and navigate to `http://your_domain.com` to see your Angular application running.
That's it! Your Angular application should now be set up and running on Nginx. Remember to update your DNS settings if you're using a domain name to point to your server's IP address.