在localhost上为meteor开发设置(https)SSL
如何创build一个自签名的SSL证书在Mac 10.9的本地服务器上使用?
我需要我的本地主机作为https://localhost
我正在使用linkedin API。 这里解释了在本地主机上需要ssl的function。 https://developer.linkedin.com/documents/exchange-jsapi-tokens-rest-api-oauth-tokens
简而言之,在客户端授权我的应用程序访问他们的数据之后,linkedin会向客户端发送不记名令牌。 linkedin的内置JavaScript库会自动发送这个cookie到我的服务器/后端。 这个json文件信息被用于用户authentication。
但是,如果服务器不是https,linkedin将不会发送私人cookie。
使用应用程序的http-proxy
ontop,可以在dev / prod模式下工作的快速简单的解决scheme。
1)jointarang:ssl
包
meteor add tarang:ssl
2)将您的证书和密钥添加到您的应用/private
目录中,例如/private/key.pem
和/private/cert.pem
然后在你的/服务器的代码
Meteor.startup(function() { SSLProxy({ port: 6000, //or 443 (normal port/requires sudo) ssl : { key: Assets.getText("key.pem"), cert: Assets.getText("cert.pem"), //Optional CA //Assets.getText("ca.pem") } }); });
然后启动您的应用程序并加载https://localhost:6000
。 请确保不要混淆https和http,因为它们是单独服务的。
有了这个我假设你知道如何创build自己的自签名证书,有如何做到这一点的资源负载。 以防万一这里有一些链接。
- http://www.akadia.com/services/ssh_test_certificate.html
- https://devcenter.heroku.com/articles/ssl-certificate-self
自签名证书的替代scheme:最好为您的应用程序域使用官方证书,并使用/etc/hosts
在本地计算机上创build回送 。 这是因为它需要在dev和prod之间切换证书。
或者你可以只使用ngrok端口转发:)
1)启动你的服务器(即在localhost:3000)
2)从命令行启动ngrok:./ngrok http 3000
这应该给你的http和https的URL从任何设备访问
其他解决scheme是使用NGINX 。 以下步骤在Mac El Capitan上进行testing,假设您的本地网站在端口3000上运行:
1.将主机添加到本地计算机:
编辑你的主机文件: vi /etc/hosts
为您的本地开发域添加一行: 127.0.0.1 dev.yourdomain.com
刷新您的cachingdscacheutil -flushcache
现在,您应该可以通过http://dev.yourdomain.com:3000访问您的本地网站
2.创build一个自签名的SSL,如下所示: http : //mac-blog.org.ua/self-signed-ssl-for-nginx/
3.安装nginx并将其configuration为将httpsstream量映射到您的本地网站:
brew install nginx
sudo nginx
现在您应该可以访问http:// localhost:8080并获取Nginx消息。
这是默认的conf,所以现在你必须设置https conf:
编辑你的conf文件
vi /usr/local/etc/nginx/nginx.conf
取消对HTTPS服务器部分的注释并更改以下行:
server_name dev.yourdomain.com;
把你刚刚创build的证书:
ssl_certificate /path-to-your-keys/nginx.pem;
ssl_certificate_key /path-to-your-keys/nginx.key;
用这个改变位置部分:
location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Client-Verify SUCCESS; proxy_set_header X-Client-DN $ssl_client_s_dn; proxy_set_header X-SSL-Subject $ssl_client_s_dn; proxy_set_header X-SSL-Issuer $ssl_client_i_dn; proxy_read_timeout 1800; proxy_connect_timeout 1800; }
重新启动nginx:
sudo nginx -s stop sudo nginx
现在你应该可以访问https://dev.yourdomain.com