我们在使用nginx时,会遇到有多个服务要进行代理,如果我们直接在nginx.conf文件中添加,配置文件会显得比较臃肿且不好维护。此时我们可以通过include的方式,为每个服务建立nginx的配置文件,这样也便于后期维护。
user root root;
#user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
然后在nginx的conf.d目录下创建配置文件,如在conf.d下创建demo.conf的配置文件
server {
listen 8081;
server_name localhost 192.168.1.1;
#charset koi8-r;
location ^~/demo/ {
root /var/opt/file;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
#root /usr/share/nginx/html;
}
}
网友评论