1. Install Homebrew
Homebrew is a package management tool under Mac OSX, just like yum under Red Hat and apt-get under Ubuntu. The specific installation only needs to be done in one step: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" (Mac comes with ruby, so Homebrew is very convenient to install)
2. Start installing Nginx
brew search nginx
brew install nginx
After the previous two steps are completed, nginx is installed. Since the default port of nginx is 8080, you can visit: localhost:8080 at this time, and you can see the welcome page of nginx.
Note: Several directories after the nginx installation is complete
Configuration file path: /usr/local/etc/nginx
Installation directory: /usr/local/Cellar/nginx
3. Access one of your own front-end projects (based on node implementation) through the domain name, basic configuration
a). The front-end project needs to be built, and it will be used by nginx after the build;
b). Configure nginx as follows:
#user nobody;
worker_processes 2;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80 default;
server_name corresponds to your own domain name
#root corresponds to the content after compiling the front-end project
location / {
root /usr/local/var/www/dist;
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
include servers/*;
}
4. Domain name access
After completing the above steps, it is inaccessible to directly access the configured domain name locally, because it involves a DNS domain name resolution problem. Therefore, in the local test, we need to modify the hosts, increase the corresponding relationship between IP and domain name, and then we can directly access our front-end project through the domain name.