安装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