1. 安装

  1. $ brew install nginx

2. 配置

  1. # Replace /usr/local/etc/nginx/nginx.conf with this. This is the
  2. # default location for Nginx according to 'nginx -h'
  3. worker_processes 1;
  4. error_log /usr/local/var/log/nginx/error.log;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. # This should be in the same directory as this conf
  10. # e.g. /usr/local/etc/nginx
  11. include mime.types;
  12. default_type application/octet-stream;
  13. # 注意这个日志格式命名为`main`,定义了日志长啥样(下面会用到)
  14. log_format main '$remote_addr - $remote_user [$time_local] $status '
  15. '"$request" $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. sendfile on;
  18. keepalive_timeout 65;
  19. # Without this I got this error: 'upstream sent too big header
  20. # while reading response header from upstream'
  21. proxy_buffer_size 128k;
  22. proxy_buffers 4 256k;
  23. proxy_busy_buffers_size 256k;
  24. server {
  25. # 端口
  26. listen 80;
  27. # 域名
  28. server_name yourDomain.com;
  29. # 日志文件以及日志对应的格式
  30. access_log /usr/local/var/log/nginx/yourDomain.com.access.log main;
  31. location / {
  32. # 这里绑定内网启动的服务
  33. proxy_pass http://0.0.0.0:3000;
  34. }
  35. }
  36. }

3. 启动

  1. # 查看帮助,可以查看当前命令位置、日志文件、默认配置文件的路径
  2. $ nginx -h
  3. # 启动服务
  4. $ sudo nginx
  5. # 停止服务
  6. $ sudo nginx -s stop

4. 文档