【下载】
https://nginx.org/en/download.html
【安装】
https://www.jb51.net/server/314841pjo.htm
#安装所需依赖
yum -y install gcc gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
tar -zxvf nginx-1.24.0.tar.gz
#提前创建好安装目录
mkdir -p /root/nginx/nginx
cd nginx-1.24.0/
./configure --with-http_ssl_module --prefix=/root/nginx/nginx
make
make install
#检测配置
/root/nginx/nginx/sbin/nginx -t
#重新加载【当配置文件有更改的时候】
nginx -s reload
【403解决】启动用户要和当前用户一样-》要更改里面的用户为当前启动登录root
https://blog.csdn.net/gb4215287/article/details/79558471
【ssl】
我用的这个
https://blog.csdn.net/u011649691/article/details/140175169
或者这个
https://baijiahao.baidu.com/s?id=1792200943616039406&wfr=spider&for=pc
【ssl安装】
mkdir -p /root/nginx/ssl
sudo yum install -y openssl
penssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
【ssl配置】
只需要替换【HTTPS 配置在最下面放开就行了】
ssl_certificate /root/nginx/ssl/server.crt;
ssl_certificate_key /root/nginx/ssl/server.key;
如下:
# HTTPS server
#
server {
listen 443 ssl;
server_name 192.168.147.131;
ssl_certificate /root/nginx/ssl/server.crt;
ssl_certificate_key /root/nginx/ssl/server.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;
}
}
然后在要使用的server-local里面添加一行就行了。地址是实际要访问的
rewrite ^(.*)$ https://192.168.147.131:443/$1 permanent;
如下:
listen 8088;
server_name 192.168.147.131;
location / {
root html;
index index.html index.htm;
rewrite ^(.*)$ https://192.168.147.131:443/$1 permanent;
}