1.安裝依賴(lài)包
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
//執(zhí)行命令
./configure
make
make install
4.啟動(dòng)nginx并訪問(wèn)
cd /usr/local/nginx/sbin
//啟動(dòng)
./nginx
5.配置反向代理并設(shè)置https
配置https需要證書(shū)航缀,可以在阿里云申請(qǐng)免費(fèi)ssl證書(shū)序调,這里證書(shū)申請(qǐng)直接跳過(guò)
//修改nginx.conf
cd /usr/local/nginx/conf
vim nginx.conf
//配置https
//添加一個(gè)server
upstream wechatlzm {
server 'ip:port';
}
server {
listen 443;
server_name '需要代理的域名名稱(chēng) 如: www.baidu.com';
ssl on;
root html;
underscores_in_headers on;
ssl_certificate cret/a.pem; //我這里配置的是阿里云申請(qǐng)的證書(shū)
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的話(huà),一定要去配置安全組規(guī)則里添加開(kāi)放443端口余舶,否則會(huì)無(wú)法訪問(wèn)的0⊙肌!