apache 安装之后配置文件位于/etc/httpd/conf/
vim /etc/httpd/conf/httpd.conf
Include /etc/httpd/extra/vhost.conf
编辑vhost.conf 新增站点:
<VirtualHost *:80>
ServerName domain.com //自己域名
ServerAlias www.domain.com //自己域名
DocumentRoot /myData/www/web3 //站点位置
<Directory "/myData/www/web3">
Options Indexes
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
可以多这种方式新增多个站点。
apache 启用压缩和缓存:
vim /etc/httpd/conf/httpd.conf
新增以下配置:
#gzip
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so
#gzip
#expires cache
LoadModule expires_module modules/mod_expires.so
#expires cache
在httpd.conf最后新增以下配置内容:
#gzip
<ifmodule mod_deflate.c>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE image/svg+xml
</ifmodule>
#gzip
#expires cache
<IfModule expires_module>
ExpiresActive on
ExpiresByType text/css A864000 //过期时间864000秒
ExpiresByType application/x-JavaScript A864000
ExpiresByType application/javascript A864000
ExpiresByType text/html A3600
ExpiresByType image/jpeg A864000
ExpiresByType image/gif A864000
ExpiresByType image/png A864000
ExpiresByType image/x-icon A864000
</IfModule>
#expires cache
安装mysql扩展
yum -y install php-mysql
支持https
1.yum install mod_ssl openssl
2.生成签名证书(可以申请免费的腾讯云证书,1年有效期)
3.修改apache配置
vim /etc/httpd/conf.d/ssl.conf
其实ssl.conf文件就是配置虚拟站点的文件
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
4.修改防火墙,增加443端口(很关键,当初忘记在防火墙中增加443端口)
强制跳转https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]