apache服务器搭建(linux搭建apache服务器)

admin 346 0

大家好,今天小编来为大家解答apache服务器搭建这个问题,linux搭建apache服务器很多人还不知道,现在让我们一起来看看吧!

一、如何配置Apache服务器

设置这个TimeOut适用于三种情况:

2、如何接收一个get请求的总时间

接收一个post和put请求的TCP包之间的时间

TCP包传输中的响应(ack)时间间隔

3、如何使得apache监听在特定的端口

修改httpd.conf里面关于Listen的选项,例如:

而如果要同时指定监听端口和监听地址,可以使用:

这样就使得apache同时监听在192.170.2.1的80端口和192.170.2.5的8000端口。

当然也可以在httpd.conf里面设置:

4、如何设置apache的最大空闲进程数

其中n是一个整数。这样当空闲进程超过n的时候,apache主进程会杀掉多余的空闲进程而保持空闲进程在n,节省了系统资源。如果在一个apache非常繁忙的站点调节这个参数才是必要的,但是在任何时候把这个参数调到很大都不是一个好主意。

来限制最少空闲进程数目来加快反应速度。

5、apache如何设置启动时的子服务进程个数

这样启动apache后就有5个空闲子进程等待接受请求。

也可以参考MinSpareServers和MaxSpareServers设置。

二、如何用apache搭建http服务器

1.如何使得apache监听在特定的端口

修改httpd.conf里面有关Listen的选项,例如:

而如果要同时指定监听端口和监听地址,可以使用:

这样就使得apache同时监听在192.170.2.1的80端口和192.170.2.5的8000端口

当然也可以在httpd.conf里面设置:

cgi脚本一般把表单里面内容作为消息的主体提交给服务器处理所以现在消息主体的大小在使用cgi的时候很有用比如使用cgi来上传文件,如果有设置:

那么上传文件超过100k的时候就会报错

3.如何使得apache对客户端进行域名验证

如果是使用on,那么只有进行一次反查,如果用double,那么进行反查的后还要进行次正向解析,只有两次的结果互相符合才行,而off就是不进行域名验证

如果为了安全,建议使用double;为了加快访问速度,建议使用off

4.如何在apache中设置session持续时间

在apache1.2以上的版本中,可以在httpd.conf里面设置:

这样就能限制每个session的保持时间是15秒session的使用可以使得很多请求都可以通过同个tcp连接来发送,节约了网络资源和系统资源

5.如何使得apache只监听在特定的ip

这样就能使得apache只监听外界对192.168.0.1的http请求如果使用:

就表明apache监听所有网络接口上的http请求

三、如何在Linux下搭建apache服务器

1、配置防火墙,开启80端口、3306端口

-A INPUT-m state--state NEW-m tcp-p tcp--dport 80-j ACCEPT#允许80端口通过防火墙

-A INPUT-m state--state NEW-m tcp-p tcp--dport 3306-j ACCEPT#允许3306端口通过防火墙

备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,

正确的应该是添加到默认的22端口这条规则的下面

##############################添加好之后防火墙规则如下所示##############################

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

-A INPUT-m state--state ESTABLISHED,RELATED-j ACCEPT

-A INPUT-m state--state NEW-m tcp-p tcp--dport 22-j ACCEPT

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

-A INPUT-m state--state NEW-m tcp-p tcp--dport 3306-j ACCEPT

-A INPUT-j REJECT--reject-with icmp-host-prohibited

-A FORWARD-j REJECT--reject-with icmp-host-prohibited

##################################################################################################

/etc/init.d/iptables restart#最后重启防火墙使配置生效

yum install httpd#根据提示,输入Y安装即可成功安装

/etc/init.d/httpd start#启动Apache

备注:Apache启动之后会提示错误:

正在启动 httpd:httpd: Could not reliably determine the server's fully qualif domain name, using::1 for ServerName

vi/etc/httpd/conf/httpd.conf#编辑

找到#ServerName www.example.com:80

修改为 ServerName www.osyunwei.com:80#这里设置为你自己的域名,如果没有域名,可以设置为localhost

chkconfig httpd on#设为开机启动

/etc/init.d/httpd restart#重启Apache

yum install mysql mysql-server#询问是否要安装,输入Y即可自动安装,直到安装完成

/etc/init.d/mysqld start#启动MySQL

chkconfig mysqld on#设为开机启动

cp/usr/share/mysql/my-medium.cnf/etc/my.cnf#拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

最后出现:Thanks for using MySQL!

MySql密码设置完成,重新启动 MySQL:

/etc/init.d/mysqld restart#重启

2、安装PHP组件,使 PHP5支持 MySQL

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt

/etc/init.d/mysqld restart#重启MySql

/etc/init.d/httpd restart#重启Apche

vi/etc/httpd/conf/httpd.conf#编辑文件

ServerTokens OS在44行修改为:ServerTokens Prod(在出现错误页的时候不显示服务器操作系统的名称)

ServerSignature On在536行修改为:ServerSignature Off(在错误页中不显示Apache的版本)

Options Indexes FollowSymLinks在331行修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

#AddHandler cgi-script.cgi在796行修改为:AddHandler cgi-script.cgi.pl(允许扩展名为.pl的CGI脚本运行)

AllowOverride None在338行修改为:AllowOverride All(允许.htaccess)

AddDefaultCharset UTF-8在759行修改为:AddDefaultCharset GB2312(添加GB2312为默认编码)

Options Indexes MultiViews FollowSymLinks在554行修改为 Options MultiViews FollowSymLinks(不在浏览器上显示树状目录结构)

DirectoryIndex index.html index.html.var在402行修改为:DirectoryIndex index.html index.htm Default.html Default.htm

index.php Default.php index.html.var(设置默认首页文件,增加index.php)

KeepAlive Off在76行修改为:KeepAlive On(允许程序性联机)

MaxKeepAliveRequests 100在83行修改为:MaxKeepAliveRequests 1000(增加同时连接数)

/etc/init.d/httpd restart#重启

rm-f/etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html#删除默认测试页

date.timezone= PRC#在946行把前面的分号去掉,改为date.timezone= PRC

disable_functions= passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#在386行列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

expose_php= Off#在432行禁止显示php版本的信息

magic_quotes_gpc= On#在745行打开magic_quotes_gpc来防止SQL注入

short_open_tag= ON#在229行支持php短标签

open_basedir=.:/tmp/#在380行设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/

/etc/init.d/mysqld restart#重启MySql

/etc/init.d/httpd restart#重启Apche

在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息!

注意:apache默认的程序目录是/var/www/html

权限设置:chown apache.apache-R/var/www/html

至此,CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)教程完成!

关于本次apache服务器搭建和linux搭建apache服务器的问题分享到这里就结束了,如果解决了您的问题,我们非常高兴。