某医院nginx 前置机(反向代理)配置

news/2024/10/17 20:19:27/

数据流图

外网访问-http://13*.*.*.12*:8087/(在出口做dnat)----http://10.*.*.230:8087/(前置机反向代理到内网)----10.1.*.230:8087(内网) 

在下配置在 10.*.*.230机器上进行配置:

一、安装nginx软件,目前版本为1.22.1-1.el7

(1)暂时放开外网,安装必要组件

[root@ca-qianzhiji ~]# sudo yum install yum-utils

Loaded plugins: fastestmirror

Determining fastest mirrors

 * base: mirrors.aliyun.com

 * extras: mirrors.163.com

 * updates: mirrors.aliyun.com

base                                                     | 3.6 kB     00:00    

extras                                                   | 2.9 kB     00:00    

updates                                                  | 2.9 kB     00:00    

(1/2): extras/7/x86_64/primary_db                          | 249 kB   00:00    

(2/2): updates/7/x86_64/primary_db                         |  20 MB   00:06    

Installed size: 2.8 M

Is this ok [y/d/N]: y

。。。。。。

(2)新建nginx更新网址配置,用于安装前服务器yum指向nginx安装源:

[nginx-stable]

name=nginx stable repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=1

enabled=1

gpgkey=https://nginx.org/keys/nginx_signing.key

module_hotfixes=true

[nginx-mainline]

name=nginx mainline repo

baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/

gpgcheck=1

enabled=0

gpgkey=https://nginx.org/keys/nginx_signing.key

module_hotfixes=true

~                                                                              


(3/3): yum-utils-1.1.31-54.el7_8.noarch.rpm                | 122 kB   00:00    

--------------------------------------------------------------------------------

Total                                              1.6 MB/s | 616 kB  00:00    

(3)暂时放开外网,安装nginx:

[root@ca-qianzhiji ~]# sudo yum install nginx

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.163.com

 * updates: mirrors.aliyun.com

nginx-stable                                             | 2.9 kB     00:00    

nginx-stable/7/x86_64/primary_db                           |  81 kB   00:01    

Resolving Dependencies

--> Running transaction check

---> Package nginx.x86_64 1:1.22.1-1.el7.ngx will be installed

--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: 1:nginx-1.22.1-1.el7.ngx.x86_64

--> Running transaction check

---> Package pcre2.x86_64 0:10.23-2.el7 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

 Package      Arch          Version                   Repository           Size

================================================================================

Installing:

 nginx        x86_64        1:1.22.1-1.el7.ngx        nginx-stable        797 k

Installing for dependencies:

 pcre2        x86_64        10.23-2.el7               base                201 k

Transaction Summary

================================================================================

Install  1 Package (+1 Dependent package)

Total download size: 998 k

Installed size: 3.3 M

Is this ok [y/d/N]: y

Downloading packages:

(1/2): pcre2-10.23-2.el7.x86_64.rpm                        | 201 kB   00:00    

warning: /var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.22.1-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 7bd9bf62: NOKEY

Public key for nginx-1.22.1-1.el7.ngx.x86_64.rpm is not installed

(2/2): nginx-1.22.1-1.el7.ngx.x86_64.rpm                   | 797 kB   00:05    

--------------------------------------------------------------------------------

Total                                              168 kB/s | 998 kB  00:05    

Retrieving key from https://nginx.org/keys/nginx_signing.key

Importing GPG key 0x7BD9BF62:

 Userid     : "nginx signing key <signing-key@nginx.com>"

 Fingerprint: 573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62

 From       : https://nginx.org/keys/nginx_signing.key

Is this ok [y/N]: y

----------------------------------------------------------------------

  Verifying  : pcre2-10.23-2.el7.x86_64                                     1/2

  Verifying  : 1:nginx-1.22.1-1.el7.ngx.x86_64                              2/2

Installed:

  nginx.x86_64 1:1.22.1-1.el7.ngx                                              

Dependency Installed:

  pcre2.x86_64 0:10.23-2.el7                                                   

Complete!

[root@ca-qianzhiji ~]#

~~~~~~~~~~~~~~~~~~~~~~

二、配置文件

/etc/nginx

在/etc/nginx/conf.d/8087.conf新建文件

~~~~~~~~~~~~~~~~~~~~~~~~

配置nginx,添加以下标红的内容。其他配置是通过 cp default.conf 8087.conf默认生成的。

upstream CAQRcode {

    server      10.1.*.230:8087;

}

server {

    listen       8087;

    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

   # location / {

   #     root   /usr/share/nginx/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   /usr/share/nginx/html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    location / {

        proxy_pass http://CAQRcode;

    }

"/etc/nginx/conf.d/8087.conf" 50L, 1120C written

~~~~~~~~~~~~~~~~~~~~

三、开通防火墙策略,我司使用的防火墙为firewalld配置,本次需要开放的为8087端口:

[root@ca-qianzhiji ~]# systemctl status firewalld

â— firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

   Active: active (running) since Thu 2023-04-06 09:21:55 CST; 45min ago

     Docs: man:firewalld(1)

 Main PID: 6288 (firewalld)

   CGroup: /system.slice/firewalld.service

           └─6288 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Apr 06 09:21:53 ca-qianzhiji systemd[1]: Starting firewalld - dynamic firewall daemon...

Apr 06 09:21:55 ca-qianzhiji systemd[1]: Started firewalld - dynamic firewall daemon.

[root@ca-qianzhiji ~]#

[root@ca-qianzhiji ~]#

[root@ca-qianzhiji ~]# firewall-cmd --permanent --add-port=8087/tcp

success

[root@ca-qianzhiji ~]# firewall-cmd --reload

 开通物理防火墙策略,完成配置。

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

四、启动nginx服务

(1)检查是否存在语法错误:

[root@ca-qianzhiji ~]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

(2)启动服务

[root@ca-qianzhiji ~]nginx

(3)如果服务已经启动,可使用reload重启加载

[root@ca-qianzhiji ~]# nginx -s reload

 

设置开机自启动

systemctl enable nginx

先用此命令启停一下 看配置是否正常

systemctl start nginx # nginx启动
systemctl stop nginx # nginx停止

直接重启服务器即可(nginx就自动重启了)

reboot

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

五、安全加固

 一、隐藏不必要的信息

大家可以看一下我的博客请求响应头,有这么一行 server: nginx,说明我用的是 Nginx 服务器,但并没有具体的版本号。由于某些 Nginx 漏洞只存在于特定的版本,隐藏版本号可以提高安全性。这只需要在配置里加上这个就可以了:

server_tokens off;

如果想要更彻底隐藏所用 Web Server,可以修改 Nginx 源码,把 Server Name 改掉再编译,具体步骤可以自己搜索。需要提醒的是:如果你的网站支持 SPDY,只改动网上那些文章写到的地方还不够,跟 SPDY 有关的代码也要改。更简单的做法是改用 Tengine 这个 Nginx 的增强版,并指定 server_tag 为 off 或者任何想要的值就可以了。另外,既然想要彻底隐藏 Nginx,404、500 等各种出错页也需要自定义。

同样,一些 WEB 语言或框架默认输出的 x-powered-by 也会泄露网站信息,他们一般都提供了修改或移除的方法,可以自行查看手册。如果部署上用到了 Nginx 的反向代理,也可以通过 proxy_hide_header 指令隐藏它:

proxy_hide_header X-Powered-By;


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

相关文章

使用Nginx搭建反向代理

引言&#xff1a;最近公司有台服务器遭受DDOS攻击&#xff0c;流量在70M以上&#xff0c;由于服务器硬件配置较高所以不需要DDOS硬件防火墙。但我们要知道&#xff0c;IDC机房是肯定不 允许这种流量一直处于这么高的&#xff0c;因为没法具体知道后面陆续攻击的流量会有多大&am…

secureCRT设置跳板机 + proxyfier代理

背景 目前有三台以下机器: 本地windows 服务器1&#xff1a;132.121.11.71 服务器2&#xff1a;132.122.11.75 服务器1 能直接访问 服务器2&#xff1b; 但是本地不能直接访问 服务器2; 现在想让本地能直接访问 服务器2中的数据库。 工具 secureCRTproxyfier 操作 1. 跳板…

【算法题】数组系列(找出数组中重复的数字、二维数组中的查找)

算法题 数组系列 一、找出数组中重复的数字1.1、题目1.2、解题思路1&#xff08;排序法&#xff09;1.3、解题思路2&#xff08;hash&#xff09;1.4、小结 二、二维数组中的查找2.1、题目2.2、理解题目2.3、解题思路2.3.1、暴力枚举2.3.2、二分查找2.3.3、对角线查询&#xff…

想做代理商吗?物联卡的起批价格、张数和注意条例你要弄清楚!

物联网时代&#xff0c;物联卡也成为了一种商机&#xff0c;想做代理商&#xff0c;物联卡的起批张数和注意条例你弄清楚了吗&#xff1f; ​ 首先&#xff0c;我们在介绍做物联卡代理要拿多少张卡之前&#xff0c;请跟小编一块先了解一下&#xff0c;做物联卡代理要满足的条…

如何代理一款游戏?想代理一款游戏应该怎么做?怎么代理一款游戏,开始游戏创业?

这几年&#xff0c;玩游戏的人越来越多。可是有的人只是玩游戏&#xff0c;有的人却从中窥得一线商机。很多玩家在玩游戏的时候多多少少都会充值。如果能代理一款游戏&#xff0c;就可以在玩家通过你的渠道进行充值的时候&#xff0c;抽取一定的佣金收益。这就是如今热门的游戏…

使用nginx做代理实现域名和ip的映射

1.nginx.conf的配置如下,nginx的监听端口是80 &#xff0c;对应项目的启动端口分别是8020对应的域名是dianyu.site&#xff0c;8020前面的ip为本机的本地ip这样访问速度比较快不能使用外网ip&#xff0c;这是第一个server的配置&#xff0c;第二个的配置对应项目端口是8080&…

nginx 反向代理的典型应用场景及方案

一、场景 现有如下的的应用需求&#xff1a; 1.利用域名代理多个端口的应用 2.利用二级目录代理多个端口的应用 3.利用二级目录代理多个IP服务器的应用 4.利用域名代理多个服务器的应用 5.利用端口代理多个服务器应用 二、场景实现 1.利用域名代理多个端口的应用 这个实现比…

利用Nginx配置反向代理

自签发SSL证书 将ssl证书统一存放在nginx配置目录下的ssl目录 [rootJumper ~]# cd /etc/nginx/ [rootJumper nginx]# mkdir ssl [rootJumper nginx]# cd ssl/生成CSR请求文件 [rootJumper ssl]# openssl genrsa -out sk3-9-ucss1.key 2048 [rootJumper ssl]# openssl req -n…