CentOS Linux Lighttpd 如何配置

  • 配置目录:/etc/lighttpd /
  • 主要配置文件:/etc/lighttpd/lighttpd.conf
  • 模块和其他配置文件目录:/etc/lighttpd/conf.d/
  • 模块配置文件:/etc/lighttpd/modules.conf
  • 默认DocumentRoot /服务器根目录:/var/www/lighttpd/
  • 默认日志目录:/var/log/lighttpd/

php/html/css/js文件文件都放在DocumentRoot

配置lighttpd

编辑/etc/lighttpd/lighttpd.conf

# vi /etc/lighttpd/lighttpd.conf

设置服务器根目录

var.server_root = "/var/www"

加载模块

将下面的行取消注释:

include "modules.conf"

将服务器端口设置为80

server.port = 80

将监听绑定到特定IP

设置监听IP

server.bind = "1.2.3.4"

设置站点的根目录

站点根目录用户存放html代码,比如html,css,js等文件

server.document-root = server_root + "/lighttpd"

如何隐藏lighttpd的服务器标签

设置服务器名称或隐藏:

server.tag = "onitroad-Web-Server"

配置lighttpd模块

# vi /etc/lighttpd/modules.conf

将php配置为fastcgi

取消注释:

include "conf.d/fastcgi.conf"

下面的模块取消注释:

server.modules = (
  "mod_access",
  "mod_alias",
  "mod_auth",
#  "mod_evasive",
  "mod_redirect",
  "mod_rewrite",
#  "mod_setenv",
#  "mod_usertrack",
)

配置php5

编辑/etc/lighttpd/conf.d/fastcgi.conf文件

# cp -v /etc/lighttpd/conf.d/fastcgi.{conf,bakup}
# vi /etc/lighttpd/conf.d/fastcgi.conf

配置FastCGI

## small server config ##
## For a large server set max-procs, PHP_FCGI_CHILDREN, and PHP_FCGI_MAX_REQUESTS as per your setup ##
server.modules += ( "mod_fastcgi" )
fastcgi.server    = ( ".php" =>
  ((
        "bin-path" => "/usr/bin/php-cgi",
        "socket" => "/tmp/php-cgi.socket." + var.PID,
        "max-procs" => 1,
        "idle-timeout" => 30,
        "bin-environment" => (
                "PHP_FCGI_CHILDREN" => "1",
                "PHP_FCGI_MAX_REQUESTS" => "50"
        ),
        "bin-copy-environment" => (
                "PATH",
                "SHELL",
                "USER"
        ),
        "broken-scriptfilename" => "enable"
  ))
)

重新启动lighttpd

如何重新启动lighttpd服务器:

# service lighttpd restart

测试

确保打开了80端口

# netstat -tulpn | grep :80

检查日志文件

# tailf /var/log/lighttpd/error.log

php测试

在/var/www/lighttpd /目录中创建hello.php:

# vi /var/www/lighttpd/hello.php

添加下面代码

<?php phpinfo(); ?>

浏览器打开下面地址

http://服务器ip/hello.php
http://server1.onitroad.local/hello.php

安装lighttpd完成。

如何在CentOS Linux上安装MySQL数据库

在CentOS Linux的系统上安装mysql数据库服务器:

# yum install mysql-server mysql

启动数据库服务,并设置开机启动

# chkconfig mysqld on
# service mysqld start

设置数据库的root用户密码

# mysqladmin -u root password NEWPASSWORDHERE

如何在CentOS Linux上安装PHP

安装php5.x和相关模块:

# yum install php-cli php-mbstring php-pecl-apc php-pdo php php-gd \
php-mysql php-xml php-bcmath php-xmlrpc php-pear php-common \
php-devel php-imap php-suhosin php-pecl-memcache

在CentOS Linux安装Lighttpd Web服务器

执行以下yum命令:

# yum install lighttpd lighttpd-fastcgi lighttpd-mod_geoip

或者

# yum --disablerepo=\* --enablerepo=epel install lighttpd lighttpd-fastcgi lighttpd-mod_geoip 

启动lighttpd服务,并设置开机自启动

# service lighttpd start
# chkconfig lighttpd on

在CentOS中开启EPEL仓库

lighttpd服务器不是基于默认CentOS或RHEL的系统的一部分。
要使用yum命令安装lighttpd,首先获取最新的epel文件:

# wget http://mirrors.aliyun.com/epel/6/i386/epel-release-6-8.noarch.rpm

安装下载的epel-release-6-8.noarch.rpm文件,执行:

# rpm -ivh epel-release-6-8.noarch.rpm

或者

# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

如何在CentOS中安装Lighttpd

如何在CentOS Linux上安装Lighttpd Web服务器?

在CentOS上,如何安装和配置Lighttpd Web服务器以及php和mysql?

Lighttpd是一种快速安全的Web服务器,已针对高性能环境进行了优化。与其他Web服务器相比,该服务器的内存占用量非常低。它包括以下高级功能:

  • 快速CGI
  • CGI
  • 验证码
  • 输出压缩
  • URL重写等
日期:2019-11-20 08:52:41 来源:oir作者:oir