CentOS8下安装Nginx同时打开流式

安装nginux

安装依赖

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

下载Nginx

wget http://nginx.org/download/nginx-1.21.3.tar.gz

tar -zxvf nginx-1.21.3.tar.gz

cd nginx-1.21.3/

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl-opt='enable-weak-ssl-ciphers'

编译安装(默认安装在/usr/local/nginx)

make

make install

cd /usr/local/nginx/sbin #进入Nginx服务的可执行目录。

./nginx

先启动看看效果

Nginx默认配置路径为/usr/local/nginx/conf  在这个位置下建立cert 安放证书

cd /usr/local/nginx/conf

mkdir cert

编辑conf

vim /usr/local/nginx/conf/nginx.conf

server {
        listen       443 ssl http2;
        server_name  域名;

        ssl_certificate      cert/证书crt;
        ssl_certificate_key  cert/证书key;

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

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

        location / {
            proxy_pass http://localhost:3000/; 
            proxy_buffering off;
        }
    }

http2

proxy_buffering off;

--with-http_v2_module

这三个是开启流式的关键

设置HTTP请求自动跳转HTTPS。

如果您希望所有的HTTP访问自动跳转到HTTPS页面,则可以在需要跳转的HTTP站点下添加以下rewrite语句。

server {

listen 80;

server_name yourdomain.com; #需要将yourdomain.com替换成证书绑定的域名。

rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。

location / {

index index.html index.htm;

}

}

:wq

保存后

cd /usr/local/nginx/sbin #进入Nginx服务的可执行目录。

./nginx -s reload #重新载入配置文件。

添加全局命令

1、vim /etc/profile

2、在profile文件中最后添加

PATH=$PATH:/usr/local/nginx/sbin export PATH 12

3、保存并退出后,重新加载profile

source /etc/profile

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值