1.安裝pcre:yum install -y pcre pcre-devel
2.安裝zlib:yum install -y zlib zlib-devel
3.安裝openssl:yum install -y openssl openssl-devel
4.安裝nginx
創(chuàng)建目錄:mkdir nginx-src && cd nginx-src
下載nginx:wget http://nginx.org/download/nginx-1.13.0.tar.gz
解壓:tar xzf nginx-1.13.0.tar.gz
進(jìn)入目錄:cd nginx-1.13.0
配置:./configure
編譯:make
安裝:make install
查看:whereis nginx 顯示:nginx: /usr/local/nginx 税朴,表示安裝目錄為/usr/local/nginx
啟動(dòng)與停止:
切換到/usr/local/nginx/sbin目錄下:
啟動(dòng) ./nginx
停止: ./nginx -s stop
查看啟動(dòng)情況: curl 127.0.0.1
出現(xiàn) 包含Welcome to nginx!的html表示啟動(dòng)成功哄酝。
5. 反向代理本地tomcat ,將本地80端口映射為8088端口
vi /usr/local/nginx/conf/nginx.conf 仁堪,添加如下配置:
server {
listen 80 default_server; server_name _;
return 444;
#過濾其他域名的請(qǐng)求,返回444狀態(tài)碼
}
server {
listen 80;
server_name wx.ppp.com; # wx.ppp.com 域名
location / { proxy_pass http://localhost:8088;
# 對(duì)應(yīng)端口號(hào)8088
}
}
配置后發(fā)現(xiàn)tomcat下的動(dòng)態(tài)資源可以正常訪問酗失,但是靜態(tài)資源不能訪問姐霍,解決辦法如下,增加代理配置:
server {
listen 80;
server_name wx.ppp.com; # wx.ppp.com域名
location /
{
proxy_pass http://localhost:8088; # 對(duì)應(yīng)端口號(hào)8088
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
expires 10m;
}
}
到此Nginx安裝配置就完成了,并且配置了反向代理Tomcat盯荤。