nginx报错问题汇总

Q:No input file specified. nginx 报错解决

“No input file specified.”原因在于使用的 PHP5.6 是 fast_cgi 模式,而在某些情况下,不能正确识别 path_info 所造成的错误。

Q:在 nginx 上启用 http2,开启 ssl,开启 HSTS

1.1 检查 OpenSSL

如果系统的 openssl 版本较低,比如低于 1.0.2 ,先升级下

wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar -zxvf openssl-1.0.2k.tar.gz
进入目录编译安装 ./config
make && make install

移除旧版本 OpenSSL

mv /usr/bin/openssl /tmp/
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

检查是否为新版本了 openssl version

OpenSSL 1.0.2k  25 May 2017

1.2 检查 nginx

这里使用的是 v1.22.0 通过 yum 安装的 nginx 版本虽然支持 http2 了,但由于使用的 openssl 版本还是低版本,所以要重新编译安装下,准备必要工具

yum -y install libxml2 libxml2-devel libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data gperftools-devel
下载解压

wget https://nginx.org/download/nginx-1.22.0.tar.gz
tar zxvf nginx-1.22.0.tar.gz

1.3 配置编译 nginx

1
./configure --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-openssl=../openssl-1.0.2k

编译安装 make && make install
查看下是否是新版本了nginx -V
关键配置文件如下,注意替换下相应的参数

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
#开启HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
listen 443 ssl http2 default_server;
server_name xiaoxiaoguo.cn www.xiaoxiaoguo.cn; #这里替换成实际的域名
ssl on;
ssl_certificate cert/214212024460825.pem; #注意证书名称
ssl_certificate_key cert/214212024460825.key;#注意证书名称
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
}

启用新配置,并验证systemctl reload nginx即可

Q:如何把 Apache htaccess 伪静态规则转换成 nginx

可以使用工具进行转换

Q:缺少 lua-nginx-module

安装 LuaJIT2,为 Nginx 添加 Lua 模块的前提需要安装 LuaJIT,这里使用的是 openresty 的 luajit2

1
2
3
4
git clone https://github.com/openresty/luajit2
cd luajit2
make
make install PREFIX=/usr/local/src/LuaJIT

看到 Successfully built LuaJIT 即成功部署,开始配置环境

1
2
3
4
5
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1

source /etc/profile
ln -s /usr/local/LuaJIT/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

nginx: [alert] detected a LuaJIT version which is not OpenResty’s; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty’s LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html))

部分查阅 nginx error 信息反馈 luajit 问题的一般都是安装错了过期版本,并不是 luajit2

现在开始安装 2 个 Nginx Module,分别是ngx_devel_kit: NDK(nginx development kit)模块和lua-nginx-module模块。

编译 Nginx

1
2
3
cd /home/nginx-1.22.0
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_v2_module --with-pcre --with-ld-opt=-Wl,-rpath,/usr/local/src/LuaJIT/lib --add-module=../ngx_devel_kit-0.3.1 --add-module=../lua-nginx-module-0.10.21
make && make install

参考:

1、Nginx 官方说明文档
2、Nginx_dynamic_module

3、Nginx 添加 Lua 模块

4、Nginx 安装 lua-nginx-module

5、Nginx 编译安装 lua-nginx-module

作者

Catooilg

发布于

2022-06-22

更新于

2025-02-10

许可协议

评论