本文主要是介绍nginx之nginx.conf基本配置1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.#user nobody;
worker_processes 2;
events {worker_connections 1024;
}http {
include mime.types;
default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream localhost{
#这里指定多个源服务器,ip:端口,80端口的话可写可不写
server 127.0.0.1:8080;
}server {
listen 80;
server_name localhost;location / {
#启动代理
proxy_pass http://localhost;
}
}
}
2.静态文件配置
#user nobody;
worker_processes 4;#推荐worker数为cpu核数,避免cpu不必要的上下文切换
events {#表示每个worker进程所能建立连接的最大值#一个nginx最大的连接数max=worker_connections*worker_processes;#对于http请求本地资源最大并发数量为max#如果http作为反向代理,最大并发数为max/2。因为每个并发会建立与客户端的连接和与后端服务的连接,会占用两个连接。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;server {listen 80;server_name localhost;#charset koi8-r;access_log logs/host.access.log main;#location / {# root html;# index index.html index.htm;# }location / {root E:/BaiduNetdiskDownload/boostrap3; #静态文件路径index index.html index.htm; #访问首页,在静态文件路径根目录}# serve static files(css|js|image..)##静态文件交给nginx处理location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|css|js|ttf|woff|woff2)${#location ~ ^/(img|javascript|js|css|flash|media|static)/ {# img|javascript|js|css|flash|media|static 对应着静态文件路径下的文件夹root E:/BaiduNetdiskDownload/boostrap3;access_log off;expires 30d;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
}
例如:访问img下的1.png图片;http://127.0.0.1/img/1.png
这篇关于nginx之nginx.conf基本配置1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!