OpenWrt默认使用uHTTPd来进行web服务,但是由于业务需求需要使用Nginx来驱动。
以下是使用nginx并开通Web网站的操作方法(OpenWrt 22.03.2 r19803-9a599fee93)
一、安装nginx
1、系统 -> software -> Update lists,搜索nginx,找到luci-nginx和luci-ssl-nginx并安装,这时可以看到uhttpd已经禁用,nginx已经启用
root@OpenWrt:~# opkg update && opkg install luci-nginx luci-ssl-nginx
二、配置nginx
1、在路径/etc/nginx/conf.d下创建xxx.conf的配置文件,xxx为任意名称,如:77bx.conf,并输入以下内容(一般是server配置)
server {
listen 1443 ssl http2;
listen [::]:1443 ssl http2;
server_name pan2.77bx.com;
index index.html;
root /www/pan2.77bx.com;
ssl_certificate /etc/nginx/conf.d/pan2.77bx.com_bundle.crt;
ssl_certificate_key /etc/nginx/conf.d/pan2.77bx.com.key;
ssl_session_cache shared:SSL:32k;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
}
2、nginx配置文件测试,并且重启
root@OpenWrt:~# nginx -t -c /etc/nginx/uci.conf root@OpenWrt:~# /etc/init.d/nginx restart
3、通过访问测试
三、nginx命令
nginx -t -c /etc/nginx/uci.conf #测试配置文件 nginx -T -c /etc/nginx/uci.conf #详细测试配置文件 /etc/init.d/nginx reload #重新读取配置 /etc/init.d/nginx restart #重启nginx服务
目前有 0 条评论