1. 安装
$ brew install nginx
2. 配置
# Replace /usr/local/etc/nginx/nginx.conf with this. This is the
# default location for Nginx according to 'nginx -h'
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
# This should be in the same directory as this conf
# e.g. /usr/local/etc/nginx
include mime.types;
default_type application/octet-stream;
# 注意这个日志格式命名为`main`,定义了日志长啥样(下面会用到)
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
# Without this I got this error: 'upstream sent too big header
# while reading response header from upstream'
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
# 端口
listen 80;
# 域名
server_name yourDomain.com;
# 日志文件以及日志对应的格式
access_log /usr/local/var/log/nginx/yourDomain.com.access.log main;
location / {
# 这里绑定内网启动的服务
proxy_pass http://0.0.0.0:3000;
}
}
}
3. 启动
# 查看帮助,可以查看当前命令位置、日志文件、默认配置文件的路径
$ nginx -h
# 启动服务
$ sudo nginx
# 停止服务
$ sudo nginx -s stop
4. 文档