web服务器lighttpd的交叉编译及配置 https
原文链接:web服务器lighttpd的交叉编译及配置lighttpd交叉编译编译环境:Ubuntu16.04 64位 交叉编译工具:arm-himix200-linux-gcc文章目录1. 交叉编译lighttpd1.1 交叉编译pcre1.2 交叉编译lighttpd2 配置lighttpd服务2.1 拷贝配置文件2.2 修改配置文件2.2.1 修改lighttpd.conf2.2.2 修改m
web服务器lighttpd的交叉编译及配置 https
一、参考文章
- web服务器lighttpd的交叉编译及配置
- 嵌入式web服务器lighttpd的交叉编译及配置–xilinx zynq
- 嵌入式web服务器lighttpd交叉编译
- lighttpd 配置 https
二、遇到的问题
-sh: ./lighttpd: not found
解决:编译器问题,更换和系统匹配的编译器。
三、Lighttpd 交叉编译移植
1.原文链接
2.正文
编译环境:Ubuntu16.04 64位
交叉编译工具:arm-himix200-linux-gcc
文章目录
1. 交叉编译lighttpd
交叉编译lighttpd过程中发现需要pcre的支持,这里先表之,我这里使用的是pcre-8.43.tar.gz,点击下载地址。
1.1 交叉编译pcre
cd ~/work
mkdir pcre.install
tar zxf pcre-8.43.tar.gz
cd pcre-8.43/
./configure --prefix=/home/jerry/work/pcre.install --host=arm-himix200-linux CC=arm-himix200-linux-gcc
make
make install
生成的~/work/pcre.install/lib/libpcre.a就是待会编译lighttpd需要的库。
1.2 交叉编译lighttpd
我下载的是lighttpd-1.4.54.tar.gz,点击下载地址。
cd ~/work
mkdir lighttpd.install
tar zxf lighttpd-1.4.54.tar.gz
cd lighttpd-1.4.54/
CC=arm-himix200-linux-gcc ./configure --prefix=/home/jerry/work/lighttpd.install/ --host=arm-himix200-linux --without-zlib --without-bzip2 PCRE_LIB=/home/jerry/work/pcre.install/lib/libpcre.a CPPFLAGS=-I/home/jerry/work/pcre.install/include
make
make install
编译并安装完成,会在~/work/lighttpd.install目录生成lib、sbin和share三个目录,其中sbin/lighttpd就是我们需要的程序。
2 配置lighttpd服务
2.1 拷贝配置文件
在~/work/lighttpd.install中手动创建目录cache、cgi-bin、config、log、sockets、upload、vhosts、webpages,并将源码包中doc/config目录下的conf.d目录、lighttpd.conf和modules.conf复制到lighttpd.install/config,
cd ~/work/lighttpd.install
mkdir -p cache cgi-bin config log sockets upload vhosts webpages
cp -rf ~/work/lighttpd-1.4.54/doc/config/conf.d ~/work/lighttpd-1.4.54/doc/config/lighttpd.conf ~/work/lighttpd-1.4.54/doc/config/modules.conf ./config
2.2 修改配置文件
2.2.1 修改lighttpd.conf
只列出修改点,做如下修改:
var.log_root = "/root/lighttpd/log"
var.server_root = "/root/lighttpd"
var.state_dir = "/root/lighttpd"
var.home_dir = "/root/lighttpd"
var.conf_dir = "/root/lighttpd/config"
var.cache_dir = server_root + "/cache"
server.use-ipv6 = "disable"
#server.username = "lighttpd"
#server.groupname = "lighttpd"
server.document-root = server_root + "/webpages"
#server.pid-file = state_dir + "/lighttpd.pid"
#include "conf.d/access_log.conf"
#server.network-backend = "sendfile"
#$HTTP["url"] =~ "\.pdf$" {
# server.range-requests = "disable"
#}
server.upload-dirs = ( "/root/lighttpd/upload" )
2.2.2 修改modules.conf
只列出修改点,做如下修改:
server.modules = (
"mod_access",
"mod_alias",
# "mod_auth",
# "mod_authn_file",
# "mod_evasive",
# "mod_setenv",
# "mod_usertrack",
# "mod_redirect",
# "mod_rewrite",
)
include "conf.d/cgi.conf"
2.2.3 修改modules.conf
只列出修改点,做如下修改:
cgi.assign = (".cgi" => "")
#cgi.assign = ( ".pl" => "/usr/bin/perl",
# ".cgi" => "/usr/bin/perl",
# ".rb" => "/usr/bin/ruby",
# ".erb" => "/usr/bin/eruby",
# ".py" => "/usr/bin/python" )
alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )
2.2.4 网页添加
在lighttpd.install/webpages目录下创建index.html文件,文件中添加如下内容:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>lighttpd Test</title>
</head>
<body>
<p>Hello World!</p>
<hr>
<p>Test Page!</p>
</body>
</html>
2.3 lighttpd服务测试
将lighttpd.install目录下的内容拷贝到开发板的/root/lighttpd/目录下,这里在修改lighttpd.conf时做了相关目录的配置,我通过nfs挂载做的拷贝,开发板上运行lighttpd,
~/lighttpd/sbin # ./lighttpd -f ../config/lighttpd.conf -m ../lib/
浏览器输入开发板IP地址,显示如下:
四、lighttpd 配置 https
1.Openssl交叉编译移植
(1)版本:openssl-1.1.1m
./Configure linux-armv4 no-asm shared no-async \
--prefix=$(pwd)/../install --cross-compile-prefix=arm-xilinx-linux-gnueabi-
make
make install
(2)参数说明
linux-armv4: 指定硬件平台,arm32位
no-asm: 在交叉编译过程中不使用汇编代码代码加速编译过程.原因是它的汇编代码是对arm格式不支持的。
shared: 生成动态连接库。
no-async: 交叉编译工具链没有提供GNU C的ucontext库
–prefix=: 安装路径,编译完成install后将有bin,lib,include等文件夹
–cross-compile-prefix=: 交叉编译工具
(3)遇到问题
openssl error: unrecognized command line option '-m64'
原因:
没有给定 os/compile,所以默认会添加 -m64 编译选项,目前很多 openwrt 都是32位系统,而且编译器基本不认 -m64 选项。
解决:
运行 ./Configure 看一下输出,根据自己的需要选择对应的 os/compiler,其他平台的比如 arm,android 等平台选择合适的参数。
2.查看lighttpd是否支持ssl
安装lighttpd之后,查看是否支持ssl,执行lighttpd -v,当有出现(ssl)字样,则表示lighttpd已支持SSL
/usr/local/lighttpd/sbin/lighttpd -v
lighttpd/1.4.63 (ssl) - a light and fast webserver
3.生成自签名证书
配置openssl库环境变量:
export LD_LIBRARY_PATH=/home/openssl/lib:$LD_LIBRARY_PATH
生成 server.pem 证书文件到当前目录
./bin/openssl req -new -x509 -keyout ssl/certs/server.pem -out ssl/certs/server.pem -days 3650 -nodes -config ./ssl/openssl.cnf
查看证书信息
./bin/openssl x509 -noout -text -in ssl/certs/server.pem
(1)命令选项和参数解读
示例中,各选项(及参数)的意义如下:
req 使用openssl的req子命令
-new 生成新的证书请求
-x509 生成自签名证书
-days 3650 自签名证书的有效期3650天(10年)【仅当使用了 -x509 选项后有效】
-keyout server.pem 私钥文件名指定为server.pem【若为运行前就已有的私钥文件且原名不是server.pem,则改名为server.pem;否则新生成的私钥文件命名为server.pem】
-out server.pem 指定输出所生成自签名证书的信息到文件,且文件名为server.pem【建议不要省略】
其中,-days,-keyout 两个选项可以省略,省略的话使用默认值,有效期默认为 30 天【由程序内部在变量初始化的时候指定,与配置文件无关】,私钥文件名的默认值由配置文件 openssl.cnf 中相关条目指定,没改过的话为 privkey.pem。
选项 -out 若是省略的话,openssl不会以文件形式输出生成的 证书/证书请求,而是会默认将文件的信息直接打印到屏幕上,这在大多数情况下,是不符合我们要求的。所以建议这个选项最好不要省略!
req子命令可以通过 -key 选项为证书请求指定使用一个已存在的私钥文件。但在示例中的情况下,虽然使用了-new 和 -x509两个选项,但没有使用 -key 选项,这时,req子命令会自动为自签名证书生成一个RSA私钥,密钥长度的默认值由配置文件 openssl.cnf 中的相关条目指定,没改过的话为 1024 bits。
(2)遇到问题
Can't open /xxx/install/ssl/openssl.cnf for reading, No such file or directory
unable to find 'distinguished_name' in config
运行openssl时提示找不到配置文件,是因为没有正确指定配置文件。
解决:
可以在命令行调用时加
-config "D:\51-n.com\openssl.conf"
4.配置lighttpd.conf ,可以通过https访问网站
在/etc/lighttpd/lighttpd.conf配置
server.modules += ( "mod_openssl" )
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = home_dir + "/cert/server.pem"
}
如果报错“please add “mod_openssl” to server.modules list in lighttpd.conf”,
请在/etc/lighttpd/modules.conf配置,增加mod_openssl
server.modules = {
"mod_openssl"
}
4.http重定向为https
此时https和http 是可以同时登陆的,如果要关闭http登陆,可以让http 80端口重定向到443端口
加入下面配置
server.modules += ( "mod_redirect" )
$HTTP["scheme"] == "http" {
# capture vhost name with regex conditiona -> %0 in redirect pattern
# must be the most inner block to the redirect rule
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
}
让http 80端口重定向到443端口,server.port = “80” , 此时再去登陆http会发现已经重定向到https
五、总结
lighttpd交叉编译配置写成脚本文件:configure-arm.sh
#! /bin/sh
CC=arm-xilinx-linux-gnueabi-gcc
AR=arm-xilinx-linux-gnueabi-ar
LD=arm-xilinx-linux-gnueabi-ld
RANLIB=arm-xilinx-linux-gnueabi-ranlib
STRIP=arm-xilinx-linux-gnueabi-strip
./configure --prefix=$(pwd)/../install \
--host=arm-xilinx-linux-gnueabi --build=i686-pc-linux \
--disable-FEATURE --enable-shared --disable-static \
--disable-lfs --disable-ipv6 --without-PACKAGE \
--without-valgrind --without-kerberos5 \
--without-zlib --without-bzip2 --without-lua \
--with-pcre --with-openssl \
PCRE_LIB=/home/osrc/Projects/tools/pcre/install/lib/libpcre.a \
CPPFLAGS=-I/home/osrc/Projects/tools/pcre/install/include
pcre交叉编译配置写成脚本文件:configure-arm.sh
#! /bin/sh
CC=arm-xilinx-linux-gnueabi-gcc
AR=arm-xilinx-linux-gnueabi-ar
LD=arm-xilinx-linux-gnueabi-ld
RANLIB=arm-xilinx-linux-gnueabi-ranlib
STRIP=arm-xilinx-linux-gnueabi-strip
./configure --prefix=$(pwd)/../install \
--host=arm-xilinx-linux-gnueabi \
--enable-utf8 --enable-unicode-properties
openssl交叉编译配置写成脚本文件:configure-arm.sh
#! /bin/sh
CC=arm-xilinx-linux-gnueabi-gcc
AR=arm-xilinx-linux-gnueabi-ar
LD=arm-xilinx-linux-gnueabi-ld
RANLIB=arm-xilinx-linux-gnueabi-ranlib
STRIP=arm-xilinx-linux-gnueabi-strip
./Configure linux-armv4 no-asm shared no-async \
--prefix=$(pwd)/../install \
--cross-compile-prefix=arm-xilinx-linux-gnueabi-
更多推荐
所有评论(0)