用WordPress搭建的个人网站启动时报错提示如下:

Nginx如果未开启SSL模块,配置Https时提示错误(the "ssl" parameter requires ngx_http_ssl_module)

[emerg] the ‘http2’ parameter requires ngx_http_v2_module in xxx.conf
the ‘http2’ parameter requires ngx_http_v2_module in xxx.conf:6

原因是没有安装HTTPS模块和HTTP2模块,那就安装下:

nginx缺少http_ssl_module模块,编译安装的时候带上–with-http_ssl_module配置就行了,HTTP2的也是同理,--with-http_v2_module。但是现在的情况是我的nginx已经安装过了,怎么添加模块???

去官网下载NGINX的最新包,上传到服务器,解压,进去NGINX目录,运行添加配置的命令,编译。

1、查看nginx原有的模块

/usr/local/nginx/sbin/nginx -V

我这个已经安装过了,所以会显示出来 

Nginx单独开启SSL模块和HTTP2模块,无需重新覆盖安装Nginx如果未开启SSL模块,配置Https时提示错误(the_nginx

 2、那么我们的新配置信息就应该这样写,运行下面的命令即可,等配置完。

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

3、编译【特别注意】这里不要进行make install,否则就是覆盖你之前的安装

make

4、备份原有已安装好的nginx

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

5、将刚刚编译好的nginx覆盖掉原有的nginx(这个时候【特别注意】这里nginx要停止状态

cp ./objs/nginx /usr/local/nginx/sbin/

6、启动nginx,仍可以通过命令查看是否已经加入成功

我这个是配置了开机自动的,具体配置可查看我之前写的文章:CentOS7.9.2009离线安装NGINX1.20.2版(附资源包)_QC班长的博客

Nginx单独开启SSL模块和HTTP2模块,无需重新覆盖安装Nginx如果未开启SSL模块,配置Https时提示错误(the_linux_02

我自己的Nginx 配置Http和Https共存 和HTTP2的例子,

HTTP2只对HTTPS生效,所以要同时配置,HTTP2的加载速度比HTTP1.1快很多 

Nginx单独开启SSL模块和HTTP2模块,无需重新覆盖安装Nginx如果未开启SSL模块,配置Https时提示错误(the_linux_03

最后附下完整的NGINX配置文件吧,由于用的是WordPress后台的是PHP的 

user  nginx nginx;
worker_processes auto;
worker_rlimit_nofile 51200;

error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;

#pid logs/nginx.pid;


events {
use epoll;
worker_connections 51200;
multi_accept on;
}


http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 1024m;
client_body_buffer_size 10m;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
server_tokens off;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;

#Gzip Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /usr/local/nginx/conf/cert/ibestidea.com.pem;
ssl_certificate_key /usr/local/nginx/conf/cert/ibestidea.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name _;
access_log /usr/local/nginx/logs/wordpress_nginx.log combined;
index index.html index.htm index.php;
root /usr/local/nginx/html/wordpress;
if ($scheme = http ) {return 301 https://$host$request_uri;}
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* ^/wp-content/uploads/.*\.php$ {
deny all;
}


location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
deny all;
}
}

}

 参考文献

0、​​3.1 HTTP 常见面试题 | 小林coding​

1、Nginx如果未开启SSL模块,配置Https时提示错误(the "ssl" parameter requires ngx_http_ssl_module)_夏婉妹妹的博客

2、[nginx] [emerg] the ‘http2‘ parameter requires ngx_http_v2_module_周雪zzZ的博客