CentOS 7.4 firewall 开启http/https 服务及SSL配置

###一、配置服务器正常开启HTTP及HTTPS

firewall http 服务开启

firewall-cmd --query-service http               ##查看http服务是否支持,返回yes或者no
firewall-cmd --add-service=http                 ##临时开放http服务
firewall-cmd --add-service=http --permanent     ##永久开放http服务
firewall-cmd --reload                           ##重启防火墙生效


操作图片
firewall https 服务开启
与上面的 http 类似,话不多说,直接上代码

firewall-cmd --add-service=https --permanent               
firewall-cmd --add-service=https --reload

firewall https 开启

###二、配置SSL

####1:证书申请
域名申请完后,在对应服务商的SSL板块申请证书,申请完下载证书,下载的文件夹下有Apache、Nginx、Tomcat等文件夹,选择自己选用的web服务器软件名称的文件,如Nginx。里面有.pem形式的公钥和.key形式的私钥。

####2、上传证书
在目录/etc/nginx/下新建文件夹cert,将.pem形式的公钥和.key形式的私钥文件放入cert文件夹下。

####3、安装OpenSSL

yum install -y openssl openssl-devel

####4、配置Nginx
进入nginx配置目录/etc/nginx/conf.d,打开default.conf文件,添加HTTP强制转HTTPS功能和在443端口下配置SSL,注意:server与server是平级关系。配置文件如下:

server {
    listen       80;
    server_name  xifajiaoyu.com; # 域名
    rewrite ^(.*) https://$host$1 permanent; #HTTP强转HTTPS

    #charset koi8-r;
    #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;
    }
}
server {
        listen 443 ssl;

        server_name www.xifajiaoyu.com ;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        ssl_certificate ssl/1_xifajiaoyu.com_bundle.crt; # 公钥目录
        ssl_certificate_key ssl/2_xifajiaoyu.com.key; # 私钥目录

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    }

或者下面自己亲测

 

server {

        listen       80;

        listen       443  ssl;

        server_name  ***.mglucky.com;

        ssl on;

        #rewrite ^(.*)$ https://$server_name$1 permanent; # HTTP强转HTTPS

        #return      301 https://$server_name$request_uri;      #这是nginx最新支持的写法

        if ($http_x_forwarded_proto = "http") {

                return 301 https://$server_name$request_uri; #http强制转https

        }        

 

        #charset koi8-r;

        ssl_prefer_server_ciphers  on;

        #access_log  logs/host.access.log  main;

        ssl_session_timeout  5m;

        location / {

            root   /usr/share/nginx/html/niushop;

            index  index.php index.html index.htm;

            try_files $uri $uri/ /index.php?s=$uri&$args;

        }

        ssl_certificate /etc/nginx/conf.d/cert/4354962_shop.xianyunshop.com.pem; # 公钥目录

        ssl_certificate_key /etc/nginx/conf.d/cert/4354962_shop.xianyunshop.com.key; # 私钥目录    

        #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/niushop;

        }

 

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

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$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;

        #}

    }


 


####5、打开防火墙443端口

firewall-cmd --zone=public --add-port=443/tcp --permanent
sudo firewall-cmd --reload

####6:重新加载Nginx
重新加载,因为一般重新配置之后,不希望重启服务,这时可以使用重新加载。

sudo systemctl reload nginx

至此完成SSL配置。
 

CentOS 7.9 安装 Zabbix 的步骤如下: 1. **更新系统**: ``` sudo yum update -y ``` 2. **添加Zabbix EPEL仓库** (如果尚未添加): ``` sudo tee /etc/yum.repos.d/zabbix.repo << EOF [zabbix] name=Zabbix Repository for RPMs baseurl=https://repo.zabbix.com/zabbix/7.4/rpm/$basearch/ gpgkey=https://repo.zabbix.com/gpg/public-key.gpg enabled=1 gpgcheck=1 priority=1 EOF ``` 3. **安装依赖包**: ``` sudo yum install -y epel-release zabbix-server-mysql zabbix-web zabbix-agent perl-DBD-MySQL ``` 如果你需要数据库支持,这里以 MySQL 为例,如果是 PostgreSQL 或其他,请替换相应包名。 4. **配置Zabbix服务器(web界面)**: - 打开 `vim /etc/zabbix/zabbix_agentd.conf` 并启用 HTTP 监控 (`ServerActive`) 和配置监听地址。 - 编辑 `/etc/zabbix/zabbix_server.conf`,设置数据库连接信息、服务器名称等。 5. **启动服务并设置开机自启**: ``` sudo systemctl start zabbix-server zabbix-agent sudo systemctl enable zabbix-server zabbix-agent ``` 6. **安装Web界面**: ``` sudo yum install -y httpd php php-fpm php-gd php-mysqlnd php-gettext mod_ssl ``` 配置 Apache(如有需要),如修改 `/etc/httpd/conf.d/zabbix.conf`。 7. **初始化 Zabbix**: - 访问 `http://your_server_ip_or_dns/zabbix`,按照向导完成初始设置。 8. **配置防火墙**: ``` sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload ``` 安装完成后,你可以通过 Web 界面管理 Zabbix,并配置监控规则。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值