安裝單機版nginx
首先下載安裝包 nginx-1.15.0.tar.gz pcre-8.38.tar.gz 首先安裝pcre
# tar zxvf pcre-8.38.tar.gz
# cd pcre-8.38
# ./configure --prefix=/home/tsaip/csss/pcre
# make
# make install
我的目錄是:/home/tsaip/csss/pcre 執行完以後開始安裝nginx
cd nginx-1.15.0
#修改配置
./configure --prefix=/home/tsaip/csss/nginx --with-pcre=../pcre-8.38
make && make install
執行完畢後nginx目錄下出現相關文件夾sbin nginx啓動 cd nginx/sbin
./nginx
如果沒有root權限則將端口號80修改爲大於1024的端口才能啓動 配置文件
cd conf
vim nginx.conf
listen 7777
修改配置文件 nginx.conf
http {
#自定義配置文件開始
upstream tomcat_service{
server 192.168.0.1:8080 weight=1;
server 192.168.0.2 :8080 weight=1;
server 192.168.0.3:8080 weight=1;
}
#自定義配置文件結束
server {
listen 8000;
server_name localhost;
location / {
# 自定義配置文件開始
proxy_pass http://tomcat_service;
proxy_set_header Host $host:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#自定義配置文件結束
}
}