nginx配置ssl去代理本机ip+端口的web应用

news/2025/4/1 8:39:36/

背景:公司安排安装了一款开源的知识库,配置完成后是IP+端口的形式访问,现在需要安装nginx并配置ssl证书,实现https访问,最后在公司DNS服务器上,对应证书域名下新建主机,将自定义的域名指向此知识库的IP。

解决方法如下:

1、编译安装nginx,并加载ssl模块
下载nginx源码包,编译安装
./configure --prefix=/etc/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
如果是第一次没装ssl模块,补充编译的,则只需要执行make即可。
本次我是第一次没装的情况,所以执行make后,需要手动更换nginx
执行完make后,编译目录下会生成objs目录,将其中的nginx与当前的做一下替换,如下:
[root@localhost nginx-1.25.4]# ll
total 828
drwxr-xr-x. 6  502 games   4096 Mar 27 10:56 auto
-rw-r--r--. 1  502 games 326027 Feb 15  2024 CHANGES
-rw-r--r--. 1  502 games 498741 Feb 15  2024 CHANGES.ru
drwxr-xr-x. 2  502 games    168 Mar 27 10:56 conf
-rwxr-xr-x. 1  502 games   2611 Feb 15  2024 configure
drwxr-xr-x. 4  502 games     72 Mar 27 10:56 contrib
drwxr-xr-x. 2  502 games     40 Mar 27 10:56 html
-rw-r--r--. 1  502 games   1397 Feb 15  2024 LICENSE
-rw-r--r--. 1 root root     414 Mar 27 13:56 Makefile
drwxr-xr-x. 2  502 games     21 Mar 27 10:56 man
drwxr-xr-x. 4 root root     187 Mar 27 13:57 objs
-rw-r--r--. 1  502 games     49 Feb 15  2024 README
drwxr-xr-x. 9  502 games     91 Feb 15  2024 src
[root@localhost nginx-1.25.4]# mv /etc/nginx/sbin/nginx /etc/nginx/sbin/nginx.bak
[root@localhost nginx-1.25.4]# cp objs/nginx /etc/nginx/sbin/
[root@localhost nginx-1.25.4]# /etc/nginx/sbin/nginx -V
nginx version: nginx/1.25.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --with-http_stub_status_module --with-http_ssl_module
查看版本可以看到nginx加载ssl模块成功
2、编辑nginx.conf
[root@localhost nginx-1.25.4]# cat /etc/nginx/conf/nginx.conf #只改动最下方https的server部分即可
#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS serverserver {listen       443 ssl;server_name  localhost;ssl_certificate      /etc/nginx/ssl/Nginx/STAR_hymson_com_integrated.crt;ssl_certificate_key  /etc/nginx/ssl/Nginx/STAR_hymson_com.key;ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_ciphers  HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers  on;location / {# root   html;# index  index.html index.htm;proxy_pass http://10.10.81.15:10086;}}
}

保存退出,重启nginx

之后再去DNS服务器上新建一个自定义的域名,并且将他指向此IP,之后网页访问就是安全连接了


http://www.ppmy.cn/news/1584159.html

相关文章

rosbag|ROS中.bag数据包转换为matlab中.mat数据类型

代码见代码 msg_dict中设置自定义消息类型 test_config中设置需要记录的具体的值 test_config中topic_name以及message_type照搬plotjuggler打开时的参数 最后生成.mat文件在matlab中进行使用

Scala课后总结(2)

Scala的基本语法 Scala没有基本数据类型与包装类型的区分,统一都是类 类型层次结构 Any 是所有类的超类,处于类型继承结构最底层 。 AnyVal 是值类型的超类,像Byte、Int等数值类型都继承自它; AnyRef 是引用类型的超类&…

机器学习算

1 KMeans聚类 什么是聚类任务 1 无监督机器学习的一种 2 目标将已有数据根据相似度划分到不同的簇 3 簇内样本彼此之间越相似,不同簇的样本之间越不相似,就越好 为什么叫KMeans聚类 1 也可以叫K均值聚类 2 K是最终簇数量,它是超参数&a…

SvelteKit 最新中文文档教程(13)—— Hooks

前言 Svelte,一个语法简洁、入门容易,面向未来的前端框架。 从 Svelte 诞生之初,就备受开发者的喜爱,根据统计,从 2019 年到 2024 年,连续 6 年一直是开发者最感兴趣的前端框架 No.1: Svelte …

基于单片机的仓库安防系统(论文+源码)

1 需求分析 仓库由于存有大量物品,因此对仓库的监控非常重要,目前仓库已经普遍装有安防系统,以保证仓库的安全,本次基于单片机的仓库安防系统设计,在功能上设计如下: 用户可通过IC卡进入仓库;系…

HTML输出流

HTML 输出流 JavaScript 中**「直接写入 HTML 输出流」**的核心是通过 document.write() 方法向浏览器渲染过程中的数据流动态插入内容。以下是详细解释&#xff1a; 一、HTML 输出流的概念 1. 动态渲染过程 HTML 文档的加载是自上而下逐行解析的。当浏览器遇到 <script&…

Unity3D ECS架构设计解析

前言 Unity3D 的 ECS&#xff08;Entity-Component-System&#xff09;架构是一种以数据驱动为核心的开发模式&#xff0c;通过将游戏对象分解为实体&#xff08;Entity&#xff09;、组件&#xff08;Component&#xff09;和系统&#xff08;System&#xff09;&#xff0c;…

性能测试理论基础-测试流程及方案设计要点

需求调研 因性能测试技术性和专业性要求比较高,通常需要性能测试人员参与需求调研和确认。 需求调研阶段,通常需要确认以下信息: 项目背景、测试范围、业务逻辑 & 数据流转(与开发确认)、系统架构、软硬件配置信息、 测试数据量(量级要一致)、外部依赖(第三方系统…