How to Deploy Application on Nginx

Summary: 

Nginx is a popular web server software that can be used to host web applications.

Using Nginx on AWS allows you to have full control over your hosting environment, as well as the ability to fine-tune your server’s performance and security settings. Additionally, Nginx is known for its high performance and low resource usage, making it a cost-effective option for hosting web applications on AWS.

Another benefit of using Nginx on AWS is the ability to easily scale your application as the number of users increases. This can be achieved by adding more EC2 instances behind a load balancer, which will automatically distribute incoming traffic across the available servers.

To use Nginx on AWS, you can launch an EC2 instance, install Nginx on it, configure it to serve your web application, and then make it accessible to users by assigning a public IP address or using a domain name.

Overall using Nginx on AWS Cloud is a good option if you are looking for a cost-effective, high-performance, and scalable way to host your web application. 

Here are the specific steps and commands for installing Nginx and deploying an application on an Ubuntu server:

  • Step 1: Update package lists:
          sudo apt update
  • Step 2:  Install Nginx:
          sudo apt install nginx
  • Step 3: Build your application: Depending on the type of application you are deploying, you will need to build it in a way that it can be served by a web server. For example, if you are deploying an Angular application, you will need to use the ng build command to create a production-ready build.
    ng build
  • Step 4: Copy your application files:
  • a. Create a new directory in Nginx’s web root directory
  • b. Copy the files generated by the build process to the new directory:
    sudo mkdir -p /var/www/html/<your-app>
    sudo cp -r <path-to-build-files>/* /var/www/html/<your-app>/
  • Step 5: Configure Nginx:
  • a. Create a new server block configuration file in the /etc/nginx/conf.d directory:
  • b. Add the following configuration to the file, replacing <your-app> with the name of your application:
    sudo nano /etc/nginx/conf.d/<your-app>.conf
server {
    listen 80;
    server_name <your-domain>;

    root /var/www/html/<your-app>;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}
  • Step 6: Test your deployment:
  • a. Test the Nginx configuration:
  • b.  If the configuration is valid, restart Nginx:
  • c. Test your deployment by accessing the server’s IP address or domain name in a web browser. Make sure everything is working as expected, and that the application is being served correctly.
      sudo nginx -t
     sudo systemctl restart nginx

Wow! – Its running on server.

Leave a comment

 

Subscribe to get the latest technology updates and services in competitor world

Masarrati IT Studio © 2023 All rights reserved (2020-2023).