MakeApacheConfCommand.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class MakeApacheConfCommand extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. //部署文件目录名称,需手动输入
  12. protected $signature = 'make:apache-conf {dir}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '自动生成apache配置文件';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return mixed
  23. */
  24. public function handle()
  25. {
  26. $url = config('app.web_url');
  27. $parsedUrl = parse_url($url);
  28. $host = $parsedUrl['host'];
  29. $dir = $this->argument('dir');
  30. $project = base_path();
  31. $project = explode('/', $project);
  32. array_pop($project);
  33. $project[] = $dir;
  34. $project = implode('/', $project);
  35. $conf =
  36. '<VirtualHost *:80>
  37. DocumentRoot "'.$project.'/public/"
  38. ServerName '.$host.'
  39. Alias "/resources/" "'.$project.'/resources/upload/"
  40. Alias "/admin" "'.$project.'/public/dist"
  41. Alias "/static/" "'.$project.'/public/dist/static/"
  42. ErrorLog logs/mp-website-admin-error_log
  43. CustomLog logs/mp-website-admin-access_log combined
  44. <Directory "'.$project.'/public/">
  45. AllowOverride All
  46. Require all granted
  47. </Directory>
  48. <Directory "'.$project.'/resources/upload/">
  49. RewriteEngine On
  50. RewriteCond %{QUERY_STRING} responseContentType=application%2Foctet-stream [NC]
  51. RewriteRule .* - [E=DOWNLOAD:yes]
  52. Header set Content-Disposition "attachment" env=DOWNLOAD
  53. AllowOverride All
  54. Require all granted
  55. </Directory>
  56. <Directory "'.$project.'/public/dist">
  57. AllowOverride All
  58. DirectoryIndex index.html
  59. Require all granted
  60. </Directory>
  61. <Directory "'.$project.'/public/dist/static/">
  62. AllowOverride All
  63. Require all granted
  64. </Directory>
  65. </VirtualHost>
  66. <VirtualHost *:443>
  67. DocumentRoot "'.$project.'/public/"
  68. ServerName '.$host.'
  69. Alias "/resources/" "'.$project.'/resources/upload/"
  70. Alias "/admin" "'.$project.'/public/dist"
  71. Alias "/static/" "'.$project.'/public/dist/static/"
  72. LimitRequestLine 40940
  73. LimitRequestFieldSize 40940
  74. SSLEngine on
  75. SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
  76. SSLCertificateFile "/etc/httpd/cert/matchexpo.cn/matchexpo.cn.crt"
  77. SSLCertificateKeyFile "/etc/httpd/cert/matchexpo.cn/matchexpo.cn.key"
  78. SSLCertificateChainFile "/etc/httpd/cert/matchexpo.cn/CA-Bundle.crt"
  79. #SSLCACertificateFile "/etc/httpd/cert/call/TencentQQAuthCA.crt"
  80. #SSLVerifyClient require
  81. <FilesMatch "\.(cgi|shtml|pl|asp|php)$">
  82. SSLOptions +StdEnvVars
  83. </FilesMatch>
  84. BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
  85. <Directory "'.$project.'/public/">
  86. Options FollowSymLinks
  87. AllowOverride All
  88. Order allow,deny
  89. Allow from all
  90. </Directory>
  91. <Directory "'.$project.'/resources/upload/">
  92. RewriteEngine On
  93. RewriteCond %{QUERY_STRING} responseContentType=application%2Foctet-stream [NC]
  94. RewriteRule .* - [E=DOWNLOAD:yes]
  95. Header set Content-Disposition "attachment" env=DOWNLOAD
  96. AllowOverride All
  97. Require all granted
  98. </Directory>
  99. <Directory "'.$project.'/public/dist">
  100. AllowOverride All
  101. DirectoryIndex index.html
  102. Require all granted
  103. </Directory>
  104. <Directory "'.$project.'/public/dist/static/">
  105. AllowOverride All
  106. Require all granted
  107. </Directory>
  108. </VirtualHost>
  109. ';
  110. $path = resource_path('conf/');
  111. if (!is_dir($path)) {
  112. mkDirs($path);
  113. }
  114. $fileName = $path . $dir .'_apache.conf';
  115. file_put_contents($fileName, $conf);
  116. echo 'echo IncludeOptional '.$fileName.' >> /etc/httpd/conf/httpd.conf'.PHP_EOL;
  117. }
  118. }