preface

What if there is no local validation after the development is complete and the front end is packaged?

When deploying with Nginx, you can check the deployment locally to increase the success rate

Knowing nGINx will help you feel more confident (at least not at all) in talking to operations to find bugs during deployment and in stealing from them

The installation

Install Nginx (Homebrew) using BREW

brew update
brew search nginx
brew install nginx
Copy the code

run

Run nginx on the terminal to start the Nginx service. To start the nginx service, go to http://127.0.0.1:8080

Nginx initial page files in/usr/local/var/WWW folder to see the welcome page is/usr/local/var/WWW/index HTML file

The corresponding address configuration file in/usr/local/etc/nginx/nginx. Conf

configuration

# nginx USES port 8080 by default If it is found that port is occupied, can be used to kill using the process of change the port, also can modify the/usr/local/etc/nginx/nginx. Conf

http {
    server {
       listen       8081;
       server_name  localhost; 
       location / {
           index index.html index.htm;
           try_files$uri $uri/ /index.html; }}}Copy the code

Other configurations (in Location)

Gzip on; gzip_types text/css text/javascript application/javascript image/jpeg image/png image/gif; gzip_buffers 4 8k; gzip_min_length 1k; gzip_comp_level 9; gzip_vary on; gzip_proxied off; gzip_static on; error_log /var/log/nginx/admin.error.log; access_log /var/log/nginx/admin.access.log; expires -1; Add_header cache-control no-cache; add_header "Access-Control-Allow-Origin" $http_origin; * add_header "access-control-allow-methods" "*"; Add_header "access-control-allow-headers" "*"; # Allow headers for requestsCopy the code

Nginx common commands

  • opennginx
  • Restart the nginxnginx -s reloadEach configuration change takes effect only after a restart
  • Close the nginxnginx -s stop