1)安装nginx
➜ ~ brew search nginx
==> Formulae
nginx
➜ ~ brew install nginx
2)本地安装localhost证书(此命令会生成两个文件localhost+2.pem, localhost+2-key.pem)
brew install nss mkcert
mkcert -install
mkcert localhost 127.0.0.1 ::1
3)修改nginx的配置文件配置https,路径在: /usr/local/etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream cocos {
server localhost:7456;
}
server {
listen [::]:8456 ssl;
server_name cocos_proxy;
location / {
proxy_pass http://cocos;
proxy_set_header Host $host:$server_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_max_temp_file_size 0;
proxy_buffering off;
}
ssl_certificate /Users/jianan/localhostCerts/localhost+2.pem;
ssl_certificate_key /Users/jianan/localhostCerts/localhost+2-key.pem;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
}
include servers/*;
}
4)nginx操作
启动nginx
nginx
修改完nginx后重启(之前必须启动过nginx,不然报错)
nginx -s reload
停止nginx
pkill -9 nginx
5)浏览器访问反向代理的地址
https://localhost:8456/