Nginx(九)-- Nginx實際使用配置
阿新 • • 發佈:2017-07-07
cal ddr conn access 增加 依然 worker ref tom
1.由於在nginx中需要配置很多東西,就會使得nginx.conf配置文件過於臃腫,所以我們會將配置文件合理的切分。大體的配置依然在nginx.conf中,其他的配置會放在etc下面的目錄中。
2.etc文件中一般是放置配置文件的,所以 在 etc 中新建目錄
mkdir -p /etc/nginx/conf.d
cd /etc/nginx/conf.d
創建一個文件:vim virtual.conf ,創建一個虛擬主機配置文件
3.將nginx.conf中 註釋掉的配置 全部刪除掉,並將 upstream 和 server 段 復制到 /etc/nginx/conf.d/virtual.conf中。如下:
1)nginx.conf:
worker_processes 4;
events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log logs/access.log main; sendfile on; keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; # 增加這一個,引用/etc/nginx/conf.d 下面所有的配置文件
}
2) virtual.conf:
upstream tomcat { server 192.168.80.128:8088; server 192.168.80.128:8089; } server { listen 80; server_name localhost; location / { proxy_pass http://tomcat; } }
4.訪問 http://192.168.80.128/,出現tomcat的主頁,ok,成功!
Nginx(九)-- Nginx實際使用配置