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 | server { |
启用新配置,并验证systemctl reload nginx
即可
Q:如何把 Apache htaccess 伪静态规则转换成 nginx
可以使用工具进行转换
Q:缺少 lua-nginx-module
安装 LuaJIT2,为 Nginx 添加 Lua 模块的前提需要安装 LuaJIT,这里使用的是 openresty 的 luajit2
1 | git clone https://github.com/openresty/luajit2 |
看到 Successfully built LuaJIT 即成功部署,开始配置环境
1 | export LUAJIT_LIB=/usr/local/LuaJIT/lib |
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 | cd /home/nginx-1.22.0 |
参考: