0%

nginx-beginner-guide-for-windows

Install Nginx on Windows

  1. Download Nginx from Nginx official website.
  2. Extract the downloaded file to a folder, for example, C:\nginx.

Build your app

  1. Build your Angular app using the following command: This will generate the dist folder under your project root. for example, D:\codes\angular\angular-router.
    1
    ng build --prod

Setup Nginx

  1. Open a command prompt as an administrator.
  2. Navigate to the Nginx directory.
  3. Open the conf/nginx.conf file in a text editor.
  4. Find the http | server block and add the following line:
    1
    2
    3
    4
    5
    6
    7
    8
    server {
    listen 80;
    server_name localhost;
    location / {
    root D:/codes/angular/angular-router/dist;
    index index.html index.htm;
    }
    }

Start Nginx

  1. Open a command prompt as an administrator.
  2. Navigate to the Nginx directory.
  3. Start Nginx using the following command:
    1
    start nginx

Restart Nginx

1
nginx -s reload

Stop Nginx

1
nginx -s stop

Check Nginx configuration

1
nginx -t

If the configuration is valid, you will see a message like this:

1
2
nginx: the configuration file C:/nginx/conf/nginx.conf syntax is ok
nginx: configuration file C:/nginx/conf/nginx.conf test is successful