Nginx-配置一个简单的http虚拟服务

配置文件内容如下:

#user  nobody;

worker_processes  4; #工作进程的个数,可以配置多个,一般配置成CPU的核数

pid        logs/nginx.pid; # 此文件用于记录线程的id

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; #tcp_nopush on; keepalive_timeout 65; #连接超时时间,单位是秒 gzip on; #启用Gizp压缩 upstream nginx.test.com { #服务器集群名字 #服务器配置,weight是权重的意思,权重越大,分配的概率越大。 server 127.0.0.1:8081 weight=1; server 127.0.0.1:8082 weight=1; server 127.0.0.1:8083 weight=1; } #第一个虚拟主机,使用默认端口80 server { listen 80; server_name localhost; #随便取 charset utf-8; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /NginxStatus { #查看nginx状态 stub_status on; access_log on; auth_basic "NginxStatus"; # auth_basic_user_file conf/htpasswd; } location /Nginx/test { #访问服务 proxy_pass http://nginx.test.com; proxy_redirect default; allow 127.0.0.1; deny all; } location ~ .(jpg|png|jpeg|bmp|gif|swf|css)$ #使用本地静态资源文件和超时时间 { root img; expires 30d; break; } error_page 404 /404.html; #错误404时指向页面 error_page 500 502 503 504 /50x.html; #错误50x时指向页面 location = /50x.html { root html; } } }
原文地址:https://www.cnblogs.com/zj0208/p/6890196.html