Linux下无图形化配置万维网服务器httpd


1,启动服务并设置为自启动:

[simonsun@host ~]$ sudo /etc/rc.d/init.d/httpd start
[simonsun@host ~]$ cd /etc/rc.d/init.d/
[simonsun@host init.d]$ sudo /sbin/chkconfig --add httpd
[simonsun@host init.d]$ sudo /sbin/chkconfig --level 35 httpd on

2,为了外网能够访问,添加80端口为允许访问的端口到防火墙:
[simonsun@host ~]$ sudo vim /etc/sysconfig/iptables.conf
添加:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
之前。
参考链接:http://looklookme.blog.51cto.com/470472/104231

注:CentOS 6 下:

[simon_sun@gnu init.d]$ sudo vim /etc/sysconfig/iptables
iptables         iptables-config  iptables.old

添加:-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

添加后如下:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

 另外,centos5系列的图形化配置工具命令是system-config-securitylevel,含有防火墙和selinux,现在最新的6系列下的命令是system-config-firewall,并且没有设置selinux的地方,需要用命令setenforce和getenforce来设置和查看。


3,另外,默认的存储页面的目录是 /var/www/html,可以修改为自定义的路径:
[simonsun@host ~]$ sudo vim /etc/httpd/conf/httpd.conf
把 DocumentRoot "/var/www/html" 注释掉,修改成自定义的:
#DocumentRoot "/var/www/html"
DocumentRoot "/home/webpages"
然后相应的建立目录,修改权限,添加当前用户到apache组,并让组成员能够修改文件,方便添加文件。重启动httpd服务:

[simonsun@host ~]$ sudo /usr/sbin/usermod -G apache -a simonsun

(或者把运行httpd的用户apache添加到simonsun所属的用户组simon也可以,日后如果有其他用户写的文件也需要被httpd访问到,添加到simonsun所属的用户组simon就可以了,当然得设置权限为chmod g+rx:

sudo /usr/sbin/usermod -G simon -a apache )

 

这一步执行后需要注销一下当前登录的pts,或者注销xwindow桌面。
[simonsun@host ~]$ sudo mkdir /home/webpages
[simonsun@host ~]$ sudo chown apache.simonsun /home/webpages/ -Rf
[simonsun@host ~]$ sudo chmod ug+rwx /home/webpages/ -Rf
[simonsun@host ~]$ sudo chmod o+rx /home/webpages/ -Rf

[simonsun@host ~]$ sudo /etc/rc.d/init.d/httpd restart

ok!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值