Redhat以及centos版本安装命令(实验用)
yum install –y httpd
主配置文件:
cat /etc/httpd/conf/httpd.conf
ServerRoot “/etc/httpd” #服务的根目录,后面的衍生目录在以目录为根
Listen 80 #默认监听80端口
ServerAdmin [email protected] #管理员邮箱
ServerName www.XXX.com:80 #网站域名
IncludeOptional conf.d/*.conf #拓展配置文件路径及命名方法
eg: /etc/httpd/conf.d/XXX.conf*
Web内容文件目录:
*/var/www/html/index.html*
软链接网站目录:
*适用场景:/var/磁盘容量不够…….
mkdir /local
echo qintest > /local/index.html
semanage fcontext -a -t httpd_sys_content_t ‘/local(/.*)?’
restorecon -vvFR /local #有selinux服务情况下
ln -s /local/ /var/www/html/filename*
基于域名虚拟主机:
将www.myweb1.com 和www.myweb2.com 托管在同一台服务器
mkdir /var/www/myweb1
mkdir /var/www/myweb2
echo web1 > /var/www/myweb1/index.html
echo web2 > /var/www/myweb2/index.html
配置文件模板 : /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
在拓展配置文件目录下做一份0.conf的模板文件 例如:
vim /etc/httpd/conf.d/0.conf
<VirtualHost 192.168.100.1:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html"
ServerName 192.168.100.1
ErrorLog "/var/log/httpd/192.168.100.1-error_log"
CustomLog "/var/log/httpd/192.168.100.1-access_log" common
</VirtualHost>
cp /etc/httpd/conf.d/0.conf /etc/httpd/conf.d/web1.conf #拷贝配置文件并修改相应内容
DocumentRoot "/var/www/web1" #网站默认文件夹
ServerName www.myweb1.com #网站域名
cp /etc/httpd/conf.d/0.conf /etc/httpd/conf.d/web2.conf #复制并且配置相应内容
DocumentRoot "/var/www/web2" #网站默认文件夹
ServerName www.myweb2.com #网站域名
配置文件模板 :
虚拟主机配置文件:/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
做SSL时用到的配置文件模板:/etc/httpd/conf.d/ssl.conf
注
此教程由博主入门学习参考用,欢迎各位大神指正,也欢迎有需要的朋友参考。