| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- class MakeApacheConfCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- //部署文件目录名称,需手动输入
- protected $signature = 'make:apache-conf {dir}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '自动生成apache配置文件';
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $url = config('app.web_url');
- $parsedUrl = parse_url($url);
- $host = $parsedUrl['host'];
- $dir = $this->argument('dir');
- $project = base_path();
- $project = explode('/', $project);
- array_pop($project);
- $project[] = $dir;
- $project = implode('/', $project);
- $conf =
- '<VirtualHost *:80>
- DocumentRoot "'.$project.'/public/"
- ServerName '.$host.'
- Alias "/resources/" "'.$project.'/resources/upload/"
- Alias "/admin" "'.$project.'/public/dist"
- Alias "/static/" "'.$project.'/public/dist/static/"
- ErrorLog logs/mp-website-admin-error_log
- CustomLog logs/mp-website-admin-access_log combined
- <Directory "'.$project.'/public/">
- AllowOverride All
- Require all granted
- </Directory>
- <Directory "'.$project.'/resources/upload/">
- RewriteEngine On
- RewriteCond %{QUERY_STRING} responseContentType=application%2Foctet-stream [NC]
- RewriteRule .* - [E=DOWNLOAD:yes]
- Header set Content-Disposition "attachment" env=DOWNLOAD
- AllowOverride All
- Require all granted
- </Directory>
- <Directory "'.$project.'/public/dist">
- AllowOverride All
- DirectoryIndex index.html
- Require all granted
- </Directory>
- <Directory "'.$project.'/public/dist/static/">
- AllowOverride All
- Require all granted
- </Directory>
- </VirtualHost>
- <VirtualHost *:443>
- DocumentRoot "'.$project.'/public/"
- ServerName '.$host.'
- Alias "/resources/" "'.$project.'/resources/upload/"
- Alias "/admin" "'.$project.'/public/dist"
- Alias "/static/" "'.$project.'/public/dist/static/"
- LimitRequestLine 40940
- LimitRequestFieldSize 40940
- SSLEngine on
- SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
- SSLCertificateFile "/etc/httpd/cert/matchexpo.cn/matchexpo.cn.crt"
- SSLCertificateKeyFile "/etc/httpd/cert/matchexpo.cn/matchexpo.cn.key"
- SSLCertificateChainFile "/etc/httpd/cert/matchexpo.cn/CA-Bundle.crt"
- #SSLCACertificateFile "/etc/httpd/cert/call/TencentQQAuthCA.crt"
- #SSLVerifyClient require
- <FilesMatch "\.(cgi|shtml|pl|asp|php)$">
- SSLOptions +StdEnvVars
- </FilesMatch>
- BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
- <Directory "'.$project.'/public/">
- Options FollowSymLinks
- AllowOverride All
- Order allow,deny
- Allow from all
- </Directory>
- <Directory "'.$project.'/resources/upload/">
- RewriteEngine On
- RewriteCond %{QUERY_STRING} responseContentType=application%2Foctet-stream [NC]
- RewriteRule .* - [E=DOWNLOAD:yes]
- Header set Content-Disposition "attachment" env=DOWNLOAD
- AllowOverride All
- Require all granted
- </Directory>
- <Directory "'.$project.'/public/dist">
- AllowOverride All
- DirectoryIndex index.html
- Require all granted
- </Directory>
- <Directory "'.$project.'/public/dist/static/">
- AllowOverride All
- Require all granted
- </Directory>
- </VirtualHost>
- ';
- $path = resource_path('conf/');
- if (!is_dir($path)) {
- mkDirs($path);
- }
- $fileName = $path . $dir .'_apache.conf';
- file_put_contents($fileName, $conf);
- echo 'echo IncludeOptional '.$fileName.' >> /etc/httpd/conf/httpd.conf'.PHP_EOL;
- }
- }
|