linux安装nginx,配置反向代理并设置https
2020-12-02 本文已影响0人
lzm_CX330
1.安装依赖包
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下载并解压安装包
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
//将解压好的包移到local目录下
mv nginx-1.13.7 /usr/local/
3.安装nginx
cd nginx-1.13.7
//执行命令
./configure
make
make install
4.启动nginx并访问
cd /usr/local/nginx/sbin
//启动
./nginx
启动成功
5.配置反向代理并设置https
配置https需要证书,可以在阿里云申请免费ssl证书,这里证书申请直接跳过
//修改nginx.conf
cd /usr/local/nginx/conf
vim nginx.conf
//配置https
//添加一个server
upstream wechatlzm {
server 'ip:port';
}
server {
listen 443;
server_name '需要代理的域名名称 如: www.baidu.com';
ssl on;
root html;
underscores_in_headers on;
ssl_certificate cret/a.pem; //我这里配置的是阿里云申请的证书
ssl_certificate_key cret/a.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 15m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
proxy_pass http://wechatlzm;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HTTP-X-Forwarded-For $remote_addr;
}
}
//保存退出
cd ../sbin
//重启nginx
./nginx -s reload
使用的阿里云ecs的话,一定要去配置安全组规则里添加开放443端口,否则会无法访问的!!