nginx/conf/nginx.conf
最简配置说明
代码
nginx/conf/nginx.conf
worker_processes 1; #工作进程个数;一般对应CPU内核对应一个worker_processes;太多反而让效率变差;
# 事件驱动模块;
events {
worker_connections 1024;#设置每个worker_processes对应多少个联接;
}
# 网络请求模块;
http {
include mime.types;#把当前目录中的mime.types配置文件引入到当前配置文件中; mime.types中放置的是请求头,表明请求的后缀在浏览器中是如何作处理的,是下载还是展示;
default_type application/octet-stream;#如果浏览器当前请求的文件不包含在`types`中,则是以`application/octet-stream`格式流的方法传递给浏览器;
sendfile on;#指的是数据零拷贝,即不需求复制和拷贝,直接
keepalive_timeout 65;#表示的是保持连接超时的时间;
# 表示一个服务器虚拟主机vhost的配置;一个nginx可以对应多个主机;一个主机表示一个独立站点,有自己独立的根目录;可以通过不同端口号区分不同的主机;
server {
listen 80;#表示当前虚拟主机监听到的端口号;
server_name localhost;#当前主机的主机名,可以用域名或主机名;
# 表示uri,如一个域名后的子目录或子路径;//如`http://fang.com/uri1/uri2.html`中`/uri1/uri2.html`就叫做uri即资源;
location / {
root html;#表示当前uri的根目录;而`html`在这里则是相对目录,相对于当前nginx应用程序的根目录;如当前配置文件在`/usr/local/nginx/conf/nginx.conf`,则是相对于`/usr/local/nginx/`;
index index.html index.htm;#表示访问当前uri下的默认页;即如果`/`没有对应的html文件,则取`/index.html`或`/index.htm`;
}
error_page 500 502 503 504 /50x.html;#错误页;表示发生服务器错误如500或502或503或504时,会转向到的地址;
# 表示`/50x.html`的uri资源配置;
location = /50x.html {
root html;#表示当前uri的根目录;
}
}
}
/usr/local/nginx/conf/mime.types
# 显示浏览器要处理的方式对应的文件名;
types {
text/html html htm shtml;#表示html与htm与shtml要以`text/html`的协议方式来进行解析;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/avif avif;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/wasm wasm;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;#表示bin与exe与dll在浏览器中是以`application/octet-stream`数据流的方式来进行下载的;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}