nginx的如果有多个server模块都配置在同一个nginx.conf文件会显得比较臃肿,后续维护起来也会比较困难,所以可以将内容写入到多个配置文件中然后在nginx.conf文件中通过include命令引入。
1.nginx.conf配置文件内容
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
log_format logtest 'the log test:$request_uri';
#access_log /var/log/nginx/test.log logtest;
sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
2.testServer.conf 配置文件内容
upstream s1{
server 192.168.72.1:8081;
server 192.168.72.1:8082;
}
upstream s2{
server 192.168.72.1:8080;
}
server {
listen 8080;
server_name localhost;
location /app {
proxy_pass http://s2;
}
location / {
proxy_pass http://s1;
}
}