linux安装nginx,配置反向代理并设置https

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

linux安装nginx,配置反向代理并设置https
文章图片
启动成功 5.配置反向代理并设置https
配置https需要证书,可以在阿里云申请免费ssl证书,这里证书申请直接跳过
//修改nginx.conf cd /usr/local/nginx/conf vim nginx.conf //配置https //添加一个server upstream wechatlzm { server'ip:port'; } server { listen443; server_name'需要代理的域名名称如: www.baidu.com'; ssl on; root html; underscores_in_headers on; ssl_certificatecret/a.pem; //我这里配置的是阿里云申请的证书 ssl_certificate_keycret/a.key; ssl_session_cacheshared:SSL:1m; ssl_session_timeout15m; ssl_ciphersHIGH:!aNULL:!MD5; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_cipherson; location / { roothtml; indexindex.html index.htm; proxy_pass http://wechatlzm; proxy_set_headerHost$host; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerHTTP-X-Forwarded-For$remote_addr; } } //保存退出 cd ../sbin //重启nginx ./nginx -s reload

【linux安装nginx,配置反向代理并设置https】使用的阿里云ecs的话,一定要去配置安全组规则里添加开放443端口,否则会无法访问的!!

    推荐阅读