手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:docker

COPY:Supporting multiple TLDs in Laravel Valet

 因为最近在用valet,然后把MAMP PRO都干掉了(不能怪我啊,实在是MAMP PRO6的一些使用太反人类了。。。不知道作者是怎么想的),但现在想想反正也就是这样简单的使用,干脆就用valet了算了。其实也可以用laravel sail的。但因为4月份之前,M1版的mac上的docker都不正常。所以,就暂时放弃了,现在用用valet也算OK。80%的情况下都OK

创建个目录,valet link一下就完事了。因为现在都是laravel的项目,用起来也算方便,毕竟也是官方的工具。但因为我用frp,所以我设置valet tld 真实的域名(比如:xxx.com),这就造成,我访问demo.xxx.com,访问的是127.0.0.1,然后我映射在外面的server也是demo.xxx.com,其实这一切都OK了。然而问题是,有时候我要测试真实域名,比如就是 demo.xxx.com ,我就只能打开全局梯子。这样我访问demo.xxx.com才对应了 frp的域名。

听起来有点绕口令,说白了就是,因为用了真实域名,所以我默认访问都是本地,但外网访问我都是真实的。而我如果要测试真实的网址,反而还要爬个梯子。虽然影响不大,但还是想换换,于是我就想,valet 是不是可以允许绑定两个域名?这样的话,是不是就全解决了?本地测试一个域名,一个域名公开对外。

找了一些文章,发现默认是不支持,但有人通过hack的方法(说白了就是改模板,改配置改代码。。。。)支持了。原文在这里:https://medium.com/@simonhamp/supporting-multiple-tlds-in-laravel-valet-e3d2a963c613

我简单的COPY了一下,没排版,要看详细的,还是直接看原版吧:

XML/HTML代码
  1. Valet is great.  
  2. Occasionally though I need an app to respond on a different TLD to the default one. And there are even times when it makes sense to have an app respond on multiple TLDs (e.g. to prove some multi-domain functionality).  
  3. You may have some secure assets hosted by a third-party that requires domain verification (FontAwesome Pro). In development, that may mean it’s easier to be using the same domain as other devs on the team than add loads of different dev domains to the service’s whitelist.  
  4. In the current release of Valet, this kind of functionality isn’t natively available. Even in third-party packages like Valet+, this isn’t supported. But with a few quick changes it’s easily possible. Let me show you how.  
  5. Dnsmasq  
  6. First we’ll need to update the Dnsmasq config so that it will handle multiple TLDs.  
  7. Turns out this is really easy. Valet holds some config in ~/.config/valet/dnsmasq.conf.  
  8. In there we just need to add some config for each TLD we want to support. Add the following two lines for every TLD you want to support. Replace {tld} with the TLD, unsurprisingly.  

  9. address=/{tld}/127.0.0.1  
  10. listen-address=127.0.0.1  

  11. Then restart Dnsmasq:  

  12. sudo brew services restart dnsmasq  

  13. Valet  
  14. Now we just need to update the Valet code to support multiple domains.  
  15. Firstly, we’re going to add some values to our ~/.config/valet/config.json. I’ve opted for simply adding keys rather than changing any existing one. I’ve added a tlds array. This will be used later.  

  16. {  
  17.     ...  
  18.     "tlds": [  
  19.          "tld1",  
  20.          "tld2"  
  21.     ]  
  22. }  

  23. Then we just need to edit some Valet files and run some commands.  
  24. All of these edits I’m making directly in my globally-installed Valet (~/.composer/vendor/laravel/valet/).  

  25. // server.php, line 70  
  26. $siteName = basename(  
  27.     // Filter host to support wildcard dns feature  
  28.     valet_support_wildcard_dns($_SERVER['HTTP_HOST']),  
  29.     '.'.$tld  
  30. );  
  31. // change to:  
  32. foreach ($valetConfig['tlds'] as $tld) {  
  33.     if (strpos($_SERVER['HTTP_HOST'], '.'.$tld) === false) {  
  34.         continue;  
  35.     }  
  36.     $siteName = basename(  
  37.         // Filter host to support wildcard dns feature  
  38.         valet_support_wildcard_dns($_SERVER['HTTP_HOST']),  
  39.         '.'.$tld  
  40.     );  
  41. }  

  42. This just allows the server to respond to whichever one of the TLDs we want to support.  
  43. Now let’s update the CLI so we can generate and remove SSL certs for all of the TLDs (valet secure and valet unsecure commands). Firstly, secure:  

  44. // cli/valet.php, line 145, secure command  
  45. $app->command('secure [domain]', function ($domain = null) {  
  46.     $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];  
  47.     Site::secure($url);  
  48.     Nginx::restart();  
  49.     info('The ['.$url.'] site has been secured with a fresh TLS certificate.');  
  50. })->descriptions('Secure the given domain with a trusted TLS certificate');  
  51. // change to:  
  52. $app->command('secure [domain]', function ($domain = null) {  
  53.     $urls = [];  
  54.     foreach (Configuration::read()['tlds'] as $tld) {  
  55.         $url = ($domain ?: Site::host(getcwd())).'.'.$tld;  
  56.         Site::secure($url);  
  57.         $urls[] = $url;  
  58.     }  
  59.     Nginx::restart();  
  60.     $urls = implode(', ', $urls);  
  61.     info('The ['.$urls.'] site has been secured with a fresh TLS certificate.');  
  62. })->descriptions('Secure the given domain with a trusted TLS certificate');  

  63. And now the unsecure command:  
  64. // cli/valet.php, line 158, unsecure command  
  65. $app->command('unsecure [domain]', function ($domain = null) {  
  66.     $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];  
  67. Site::unsecure($url);  
  68. Nginx::restart();  
  69. info('The ['.$url.'] site  will now serve traffic over HTTP.');  
  70. })->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');  
  71. // change to:  
  72. $app->command('secure [domain]', function ($domain = null) {  
  73.     $urls = [];  
  74.     foreach (Configuration::read()['tlds'] as $tld) {  
  75.         $url = ($domain ?: Site::host(getcwd())).'.'.$tld;  
  76.         Site::secure($url);  
  77.         $urls[] = $url;  
  78.     }  
  79.     Nginx::restart();  
  80.     $urls = implode(', ', $urls);  
  81.     info('The ['.$urls.'] site will now serve traffic over HTTP.');  
  82. })->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');  

  83. Finally, run the following command:  

  84. valet restart 

  85. Enjoy

 

以上是仅复制未排版,嫌丑的看原文:https://medium.com/@simonhamp/supporting-multiple-tlds-in-laravel-valet-e3d2a963c613

如果不用梯子看不了,就将就点吧

 

Tags: valet, docker, frp

cannot create/resize docker.qcow2

mac下面安装过docker,但后来删除过。然后系统又重做过。结果再次安装docker的时候报错,如题(详细 路径不贴了)

找了一下资料,各种各样的都有,最后还是选择了:
XML/HTML代码
  1. sudo rm -r /var/tmp/com.docker.vmnetd.socket  
  2. sudo rm -r ~/Library/Application\ Scripts/com.docker.helper/  
  3. sudo rm -r ~/Library/Containers/com.docker.*  
  4. sudo rm -r ~/Library/Preferences/com.docker.docker.plist  
  5. sudo rm -r ~/Library/Group\ Containers/group.com.docker/  
然后再次运行Docker,一切都解决了
 

Tags: docker

怎样在阿里云上安装docker

因为debian 7安装docker的手续比较麻烦,所以我把阿里云的系统换成了ubuntu 14.04,然后参考:https://docs.docker.com/installation/ubuntulinux/

还算比较方便:apt-get update && apt-get install docker.io,然后再改两个配置就完事了。

不过,在你运行docker run -i -t ubuntu /bin/bash的时候,会报错,说是docker -d好象没有运行,这不科学 啊,刚刚不是装好的吗?

于是ps aux|grep docker,果然没有进程,于是直接输入:docker -d,然后就发现报错了:

XML/HTML代码
  1. 2014/08/18 12:05:42 Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0'  

老规矩,内事不决问度娘,外事不决问谷歌,结果居然看到有人回复 :

大小: 46.71 K
尺寸: 500 x 174
浏览: 1741 次
点击打开新窗口浏览全图

当时这个心就碎了,心想这不科学啊,于是再google,就真的发现了:

大小: 65.11 K
尺寸: 500 x 235
浏览: 1810 次
点击打开新窗口浏览全图

OK,那就试试吧:

XML/HTML代码
  1. sudo brctl addbr docker0 # create your bridge  
  2. sudo brctl addif docker0 eth0 # mask an existing interface using the bridge  
  3. sudo ip link set dev docker0 up # bring it up - not really sure if this is necessary or is it done automatically  
  4. sudo ifconfig docker0 10.0.0.4 # give it an IP  

当然要运行brctl还是要装一个bridge-utils工具的,当然这个ubuntu会提醒你,一步步的做完后,docker 果然可以启动了。这时候再运行一下,service docker.io start,然后ps aux|grep docker,进程还活着。

于是输入:

XML/HTML代码
  1. docker run -i -t ubuntu /bin/bash  
  2. Unable to find image 'ubuntu' locally  
  3. Pulling repository ubuntu  
  4. 2014/08/18 12:16:44 Get https://index.docker.io/v1/repositories/ubuntu/images: dial tcp: lookup index.docker.io on 10.143.22.118:53: no answer from server  

咦。不能上网。其实就是上面的代码的问题,因为默认aliyun的eth0是内网IP,所以上述的

  1. sudo brctl addif docker0 eth0 # mask an existing interface using the bridge  
  2. 这里应该用eth1

重新执行一下。然后再次运行:

XML/HTML代码
  1. docker run -i -t ubuntu /bin/bash  
  2. Unable to find image 'ubuntu' locally  
  3. Pulling repository ubuntu  
  4. c5881f11ded9: Download complete   
  5. 。。。。。。。  

整个就完成了

 

Tags: docker, aliyun