See Official Guide
https://nginx.org/en/docs/beginners_guide.html
Install Nginx on macOS X
brew install nginx
Default config file & logs
By default, the config file path is /usr/local/etc/nginx/nginx.conf
.
sudo vi /usr/local/etc/nginx/nginx.conf
and the error logs path is /usr/local/var/log/nginx/error.log
.
tail -f /usr/local/var/log/nginx/error.log
Show Help
nginx -h
# or
nginx -?
Start, Stop, Reload
nginx -h
# start Nginx
nginx
# stop Nginx
nginx -s stop
# start Nginx with a.conf in current directory
nginx -p . -c a.conf
nginx -s reload
Sample configuration
#user root;
events {
}
http {
include /usr/local/etc/nginx/mime.types;
server {
listen 80;
server_name localhost;
client_max_body_size 10m;
location / {
alias /Users/wanghao/Workspace/ls-smartools-frontend/dist/;
index index.html;
}
}
}
#user root;
events {
}
http {
server {
listen 8080;
server_name localhost;
location ~ ^/qpe/(\S+)$ {
alias /Users/wanghao/Workspace/qpe/htdocs/$1.json;
}
}
}
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8081;
}
location /api/backend {
rewrite ^/api/backend/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:3100;
}
location /api/pe {
rewrite ^/api/pe/(.*)$ /qpe/$1 break;
proxy_pass http://192.168.100.6:8080;
}
}
}
Reload
nginx -s reload
停止服务
nginx -s stop
指定配置文件启动
nginx -c /usr/local/etc/nginx/xxx.conf
2021-07-20 上传文件HTTP 413错误
修改配置文件
location /api/backend {
rewrite ^/api/backend/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:3100;
client_max_body_size 8m;
}
其中client_max_body_size
设定文件上传大小为8M。
2021-09-17
app.js
报mismatch
错误
tail -f /usr/local/var/log/nginx/error.log
参考老外的解决方案
sudo nginx -s stop
sudo rm -rf /usr/local/var/run/nginx/*
sudo nginx