apache 虚拟主机配置多站点
2017-06-21 20:03
453 查看
apache 安装之后配置文件位于/etc/httpd/conf/
使用单独的文件配置虚拟主机,在 /etc/httpd/extra/文件夹下新建文件vhost.conf,并且修改httpd.conf配置文件,引入单独的虚拟主机配置文件:
Include /etc/httpd/extra/vhost.conf
编辑vhost.conf 新增站点:
可以多这种方式新增多个站点。
apache 启用压缩和缓存:
新增以下配置:
#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]
vim /etc/httpd/conf/httpd.conf
使用单独的文件配置虚拟主机,在 /etc/httpd/extra/文件夹下新建文件vhost.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]
相关文章推荐
- 在Apache下配置多个虚拟主机站点
- Apache2.2.x+tomcat单IP多域名多站点的虚拟主机配置详解(win2003环境)
- Linux环境下Apache配置多个虚拟主机挂载多站点同时运行
- Apache之——多虚拟主机多站点配置的两种实现方案
- WAMP下Apache配置httpd-vhosts虚拟主机多站点
- Linux环境下Apache配置多个虚拟主机挂载多站点同时运行
- apache的多站点虚拟主机配置方法
- Apache之——多虚拟主机多站点配置的两种实现方案
- WAMP下Apache配置httpd-vhosts虚拟主机多站点
- apache的多站点虚拟主机配置方法
- Apache2.2.x+tomcat单IP多域名多站点的虚拟主机配置详解(win2003环境)
- 基于Apache在本地配置多个虚拟主机站点
- Apache之——多虚拟主机多站点配置的两种实现方案
- Linux环境下Apache配置多个虚拟主机挂载多站点同时运行
- 基于 Apache 在本地配置多个虚拟主机,实现本地多站点访问
- Apache2.2.x+tomcat单IP多域名多站点的虚拟主机配置详解(win2003环境)
- 基于Apache在本地配置多个虚拟主机站点
- Apache2.4虚拟主机和多站点配置
- apache中使用mod_gnutls模块实现多个SSL站点配置(多个HTTPS协议的虚拟主机)
- Ubuntu下Apache多站点虚拟主机配置