安装nginx环境

  1. brew install nginx

nginx info

  1. nginx
  2. Docroot is: /usr/local/var/www
  3. The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
  4. nginx can run without sudo.
  5. nginx will load all files in /usr/local/etc/nginx/servers/.
  6. To have launchd start nginx now and restart at login:
  7. brew services start nginx
  8. Or, if you don't want/need a background service you can just run:
  9. nginx

启动nginx方式

  1. brew services start nginx
  2. or
  3. sudo nginx

nginx 运行的根目录

  1. /usr/local/var/www

修改配置

  1. /usr/local/etc/nginx/servers/

修改完成,重启

  1. sudo nginx -s reload
  2. 修改成功了

安装成功

http://localhost:8080/

  1. Welcome to nginx!
  2. If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
  3. For online documentation and support please refer to nginx.org.
  4. Commercial support is available at nginx.com.
  5. Thank you for using nginx.

解决nginx代理后没有热更新问题

如果在前端项目里面,通过NGINX配置反向代理的项目是没有热更新的,解决办法

  1. # 指定文件走websocket协议
  2. location /sockjs-node {
  3. proxy_pass http://localhost:3000;
  4. proxy_http_version 1.1;
  5. proxy_set_header Upgrade $http_upgrade;
  6. proxy_set_header Connection 'upgrade';
  7. proxy_set_header Host $host;
  8. proxy_redirect off;
  9. }