• Nginx单独开启SSL模块和HTTP2模块,无需重新覆盖安装


    用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

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

     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班长的博客-CSDN博客_pcre 安装包

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

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

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

    1. user nginx nginx;
    2. worker_processes auto;
    3. worker_rlimit_nofile 51200;
    4. error_log logs/error.log;
    5. error_log logs/error.log notice;
    6. error_log logs/error.log info;
    7. #pid logs/nginx.pid;
    8. events {
    9. use epoll;
    10. worker_connections 51200;
    11. multi_accept on;
    12. }
    13. http {
    14. include mime.types;
    15. default_type application/octet-stream;
    16. server_names_hash_bucket_size 128;
    17. client_header_buffer_size 32k;
    18. large_client_header_buffers 4 32k;
    19. client_max_body_size 1024m;
    20. client_body_buffer_size 10m;
    21. sendfile on;
    22. tcp_nopush on;
    23. keepalive_timeout 120;
    24. server_tokens off;
    25. tcp_nodelay on;
    26. fastcgi_connect_timeout 300;
    27. fastcgi_send_timeout 300;
    28. fastcgi_read_timeout 300;
    29. fastcgi_buffer_size 64k;
    30. fastcgi_buffers 4 64k;
    31. fastcgi_busy_buffers_size 128k;
    32. fastcgi_temp_file_write_size 128k;
    33. fastcgi_intercept_errors on;
    34. #Gzip Compression
    35. gzip on;
    36. gzip_buffers 16 8k;
    37. gzip_comp_level 6;
    38. gzip_http_version 1.1;
    39. gzip_min_length 256;
    40. gzip_proxied any;
    41. gzip_vary on;
    42. gzip_types
    43. text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    44. text/javascript application/javascript application/x-javascript
    45. text/x-json application/json application/x-web-app-manifest+json
    46. text/css text/plain text/x-component
    47. font/opentype application/x-font-ttf application/vnd.ms-fontobject
    48. image/x-icon;
    49. gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    50. server {
    51. listen 80;
    52. listen [::]:80;
    53. listen 443 ssl http2;
    54. listen [::]:443 ssl http2;
    55. ssl_certificate /usr/local/nginx/conf/cert/ibestidea.com.pem;
    56. ssl_certificate_key /usr/local/nginx/conf/cert/ibestidea.com.key;
    57. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    58. 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;
    59. ssl_prefer_server_ciphers on;
    60. ssl_session_timeout 10m;
    61. ssl_session_cache builtin:1000 shared:SSL:10m;
    62. ssl_buffer_size 1400;
    63. add_header Strict-Transport-Security max-age=15768000;
    64. ssl_stapling on;
    65. ssl_stapling_verify on;
    66. server_name _;
    67. access_log /usr/local/nginx/logs/wordpress_nginx.log combined;
    68. index index.html index.htm index.php;
    69. root /usr/local/nginx/html/wordpress;
    70. if ($scheme = http ) {return 301 https://$host$request_uri;}
    71. location / {
    72. try_files $uri $uri/ /index.php?$args;
    73. }
    74. rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    75. location ~* ^/wp-content/uploads/.*\.php$ {
    76. deny all;
    77. }
    78. location ~ [^/]\.php(/|$) {
    79. #fastcgi_pass remote_php_ip:9000;
    80. fastcgi_pass unix:/run/php-fpm/www.sock;
    81. fastcgi_index index.php;
    82. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    83. fastcgi_param QUERY_STRING $query_string;
    84. fastcgi_param REQUEST_METHOD $request_method;
    85. fastcgi_param CONTENT_TYPE $content_type;
    86. fastcgi_param CONTENT_LENGTH $content_length;
    87. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    88. fastcgi_param REQUEST_URI $request_uri;
    89. fastcgi_param DOCUMENT_URI $document_uri;
    90. fastcgi_param DOCUMENT_ROOT $document_root;
    91. fastcgi_param SERVER_PROTOCOL $server_protocol;
    92. fastcgi_param REQUEST_SCHEME $scheme;
    93. fastcgi_param HTTPS $https if_not_empty;
    94. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    95. fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
    96. fastcgi_param REMOTE_ADDR $remote_addr;
    97. fastcgi_param REMOTE_PORT $remote_port;
    98. fastcgi_param SERVER_ADDR $server_addr;
    99. fastcgi_param SERVER_PORT $server_port;
    100. fastcgi_param SERVER_NAME $server_name;
    101. # PHP only, required if PHP was built with --enable-force-cgi-redirect
    102. fastcgi_param REDIRECT_STATUS 200;
    103. }
    104. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    105. expires 30d;
    106. access_log off;
    107. }
    108. location ~ .*\.(js|css)?$ {
    109. expires 7d;
    110. access_log off;
    111. }
    112. location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
    113. deny all;
    114. }
    115. }
    116. }

     参考文献

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

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

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

  • 相关阅读:
    YoloV5-SPD+TensorRT:基于YoloV5-SPD的小目标检测算法训练
    【NOWCODER】- Python:列表(三)
    【小想法】第1期:模型工程化,向量相似度,早停机制,BERT微调小trick
    Linux虚拟机安装:VMware安装配置&&CentOS安装
    Java实习生常规技术面试题每日十题Java基础(五)
    Leetcode 84.柱状图中最大的矩形
    基于web的运动会综合管理系统
    云存储系统架构及优势
    GCC内联汇编及其在Linux内核中的使用
    C goto 语句
  • 原文地址:https://blog.csdn.net/qq_35624642/article/details/126442054