Macbook

GitbookEnv2021-02-16


๐Ÿ“‘ ๆ›ดๆ–ฐ node ็‰ˆๆœฌ


ๅ› ไธบๆœ‰fsevents่ญฆๅ‘Š๏ผŒ ้œ€่ฆๆ›ดๆ–ฐ macbook ็š„node็‰ˆๆœฌ 8.11 -> v13.7.0

$ brew update
$ brew upgrade node
ๆˆ–่€…๏ผš
$ sudo n latest

๐Ÿ“‘ yarn


$ yarn cache clean
$ yarn list | grep fsevents
$ yarn install --check-files
$ yarn cache clean && yarn upgrade && yarn

๐Ÿ“‘ mysql ๅ’Œ nginx ไธ work ็š„่งฃๅ†ณๆ–นๆณ•ใ€‚


$ xcode-select --install
$ brew services list
$ vi /usr/local/etc/nginx/nginx.conf
$ brew services start mysql; // start/restart/stop
$ brew services restart nginx
$ brew info nginx
$ netstat -ap tcp | grep -i listen

๐Ÿช• HTTPS protocol for localhost using NGINX in OSX

๐Ÿ“‘ ๅฎ‰่ฃ…nginx

$ brew install nginx

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login: brew services start nginx Or, if you donโ€™t want/need a background service you can just run: nginx

nginx ๅฎ‰่ฃ…ๅœจ/usr/local/Cellar/nginx/1.17.8

$ brew services restart nginx
$ sudo nginx -s reload

Important locations:

  • Add configs in -> /usr/local/etc/nginx/servers/
  • Default config -> /usr/local/etc/nginx/nginx.conf
  • Logs will be in -> /usr/local/var/log/nginx/
  • Default webroot in -> /usr/local/var/www/
  • Default listen address -> http://localhost:8080

๐Ÿ“‘ openssl


WebServer ๅœจ8000็ซฏๅฃ่ฟ่กŒ๏ผŒnginx ้€š่ฟ‡ ssl443็ซฏๅฃๅๅ‘ไปฃ็†

  1. ๅœจ mac ไธŠ็”Ÿๆˆ่ฏไนฆ๏ผš
$ openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt
  1. /etc/hosts:
127.0.0.1	localhost test.local

3.

$ openssl x509 -text -noout -in localhost.crt

4.

$ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Users/test/.localhost-ssl/localhost.crt
  1. /usr/local/etc/nginx/nginx.conf
events {}
http {
    upstream backend {
        server 127.0.0.1:8000;
    }
    server {
        server_name local.website.dev;
        rewrite ^(.*) https://local.website.dev$1 permanent;
    }
    server {
        listen               443;
        ssl                  on;
        ssl_certificate      /path-to-file/localhost.crt;
        ssl_certificate_key  /path-to-file/localhost.key;
        ssl_ciphers          HIGH:!aNULL:!MD5;
        server_name          local.website.dev;
        location / {
            proxy_pass  http://localhost:4000;
        }
    }
}

๐Ÿ“‘ ่ฎฟ้—ฎๆœฌๅœฐ SSL ็ซ™็‚น


๐Ÿ“‘ install mongodb

$ brew update
$ brew tap mongodb/brew
$ brew install mongodb-community

๐Ÿ“‘ restart

$ brew services list
$ brew services restart mongodb-community
$ brew services restart mysql

๐Ÿ“‘ command


$ brew tap heroku/brew && brew install heroku
$ heroku login

$ brew services stop mongodb-community

$ brew services restart nginx (stop, start)

$ brew install mariadb; //brew uninstall mysql;

๐Ÿ“‘ mariadb vs mysql


๐Ÿ“‘ brew install


  • heroku
  • nginx
  • mysqld (8.0)
  • mongodb

๐Ÿ“‘ nginx.conf


   1 server {
   2     listen 80;
   3
   4     server_name mydomain.com;
   5
   6     location ~ ^/myApp/(libs/|img/|js/|css/) {
   7         root /path/to/myApp/public;
   8         access_log off;
   9         expires max;
  10     }
  11
  12     location /myApp {
  13         proxy_pass http://mean-stack-ip:8080;
  14         proxy_http_version 1.1;
  15         proxy_set_header Upgrade $http_upgrade;
  16         proxy_set_header Connection 'upgrade';
  17         proxy_set_header Host $host;
  18         proxy_cache_bypass $http_upgrade;
  19     }
  20 }