linux搭建web服务器 Linux怎么搭建Web服务器
大家好,如果您还对linux搭建web服务器不太了解,没有关系,今天就由本站为大家分享linux搭建web服务器的知识,包括Linux怎么搭建Web服务器的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!
Linux怎么搭建Web服务器
1,基于apache的web服务器基础搭建:
(1)实验环境:一台ip为192.168.10.10的rhel5.9主机作为web服务器,一台ip为192.168.10.15的win7主机作为测试机
(2)查看服务主机软件是否安装
[root@ser1~]# rpm-q httpd httpd-manual httpd-devel
package httpd is not installed
package httpd-manual is not installed
package httpd-devel is not installed
(3)安装软件包
[root@ser1~]# yum install-y httpd httpd-manual httpd-devel
(4)启动服务
[root@ser1~]# service httpd start
启动httpd: [确定]
[root@ser1~]# chkconfig httpd on
(5)在win7上测试,无网页缺省下显示红帽测试页
<报错页面存放位置/var/www/error/noindex.html>
(6)打开配置文件
[root@ser1~]# vim/etc/httpd/conf/httpd.conf
可获得以下重要字段:
目录设置:
<Directory目录>....</Directory>
访问位置设置:
<LocationURL>....</Location>
虚拟主机设置:
<VirtualHost监听地址>....</VirtualHost>
常用的全局设置参数:
ServerName本站点的FQDN名称
DocumentRoot网页文档的根目录:缺省/var/www/html/
DirectoryIndex默认索引页/首页文件:一般设为index.html index.php
ErrorLog错误日志文件的位置
CustomLog访问日志文件的位置
Listen监听服务的IP地址、端口号
ServerRoot服务目录:/etc/httpd/
Timeout网络连接超时,默认 300秒
KeepAlive是否保持连接,可选On或Off
MaxKeepAliveRequests每次连接最多处理的请求数
KeepAliveTimeout保持连接的超时时限
Include可包含其他子配置文件:/etc/httpd/conf.d/
(7)创建测试网页
[root@ser1~]# vim/var/www/html/index.html
<h1>
This is a test page!!!
</h1>
~
(8)win7下测试,主页变为测试网页
2,基于apache的web服务器的访问控制:
(1)web服务的地址限制
I,rder配置项,定义控制顺序
allow,deny先允许后拒绝,缺省拒绝所有;冲突时,拒绝生效;allow不设置,拒绝所有
deny,allow先拒绝后允许,缺省允许所有;冲突时,允许生效;deny不设置,允许所有
II,Allow/Deny from配置项,设置权限
Allow from地址1地址2....
Deny from地址1地址2....
配置如下:
[root@ser1~]# vim/etc/httpd/conf/httpd.conf
331#
332 Orderallow,deny
333 Allowfrom 192.168.20.0/24
334
335</Directory>
[root@ser1~]# service httpd restart……重启服务
停止httpd: [确定]
启动httpd: [确定]
在win7上测试,测试完成并还原配置文件:
关于更多Linux的学习,请查阅书籍《linux就该这么学》。
如何在linux搭建web服务器
可以参考如下Web服务器的建立过程。示例环境及web服务器软件:
Ubuntu 12.04
LAMP(Linux,Apache,Mysql,PHP)
1、安装Apache
(1)在安装HTTP Server之前需安装APR(Apache Portable Runtime)和APR-util安装APR
$ tar zxvf apr-1.4.6.tar.gz
$ cd apr-1.4.6/
$./configure
$ make
$ sudo make install
(2)安装APR-util
$ tar zxvf apr-util-1.4.1.tar.gz
$ cd apr-util-1.4.1
$./configure–with-apr=/usr/local/apr(whereis apr)
$ make
$ sudo make install
(3)安装httpd-2.4.2.tar.bz2默认安装位置/usr/local/apache2网页放在/usr/local/apache2/htdocs配置文件/usr/local/apache2/conf/httpd.conf
$ tar jxvf httpd-2.4.2.tar.bz2
$ cd httpd-2.4.2/
$./configure
$ make
$ sudo make install
(4)启动HTTP Server$ sudo/usr/local/apache2/bin/apachectl startAH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the‘ServerName’ directive globally to suppress this message
(5)查看http是否正常运行$ netstat-a| grep httptcp 0 0*:http*:* LISTEN
(6)在浏览器输入127.0.0.1如果正常应该显示“It works!”
2、安装MySQL
(1)、下载安装mysql-5.5.25.tar.gz,默认安装位置/usr/local/mysql/
$ tar zxvf mysql-5.5.25.tar.gz
$ cd mysql-5.5.25/
$ sudo groupadd mysql
$ sudo useradd-r-g mysql mysql
$ cmake.
$ make
$ sudo make install
$ cd/usr/local/mysql/
$ sudo chown-R mysql.
$ sudo chgrp-R mysql.
$ sudo scripts/mysql_install_db–user=mysql
$ sudo chown-R root.
$ sudo chown-R mysql data/
$ sudo cp support-files/my-medium.cnf/etc/my.cnf
$ sudo cp support-files/mysql.server/etc/init.d/mysql.server
(2)、启动MySQL:
方法1:$ sudo service mysql.server start
方法2:$ sudo/usr/local/mysql/bin/mysqld_safe--user=mysql&
3、安装PHP
(1)安装下载php-5.4.4.tar.gz
$ tar zxvf php-5.4.4.tar.gz
$ cd php-5.4.4
$./configure--with-apxs2=/usr/local/apache2/bin/apxs--with-mysql--with-mysqli--enable-mbstring--with-mcrypt(可能需要安装libmcrypt-dev)
$ sudo make install
$ sudo cp php.ini-development/usr/local/lib/php.ini
(2)配置HTTP Server使之支持PHPapache配置文件/usr/local/apache2/conf/httpd.conf修改或添加如下配置
<;IfModule dir_module>
DirectoryIndex index.php
<;/IfModule>
<;FilesMatch\.php$>
SetHandler application/x-httpd-php
<;/FilesMatch>
(3)重启HTTP Server
$ sudo/usr/local/apache2/bin/apachectl restart
如何在Linux中搭建一个web服务器
web服务器的简单搭建1、安装一个可以提供web服务的软件yum-yinstallhttpd2、启动httpd服务systemctlstarthttpd3、进入主配置文件vim/etc/httpd/conf/httpd.conf在此范围内添加或删除设置,为了方便编写,编辑了一个子配置文件/etc/httpd/conf.d/httpd-vhosts.conf4、编辑子配置文件vim/etc/httpd/conf.d/httpd-vhosts.conf此路径必为conf.d/*.conf(意:为.conf后缀命名)systemctlrestarthttpd重启服务5、编辑页面测试文件在web服务中默认存放网页文件的路径:/var/chaodiquan.com/html默认网页文件名字:index.html6、浏览器测试ifconfigens33查看ens33网卡的地址在浏览器里面输入你的IP就可以看到测试文件里希望可以帮助到的哈!
OK,本文到此结束,希望对大家有所帮助。