Nginx配置文件nginx.conf的配置和理解

#user nobody; #用户名,无密码,不可登录
worker_processes 1; #设置工作进程的数量,可以是CPU个数和2倍

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


#设置一个工作进程的最大连接数,最多65535
events {
worker_connections 1024;
}


http {
#配置nginx支持哪些多媒体类型,可以在cong/mime.types中查看支持哪些多媒体。默认文件类型,流类型
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日志及存放路径,并使用上面定义的main日志格式
#access_log logs/access.log main;

sendfile on; #开启高效文件传输模式
#tcp_nopush on; #防止网络阻塞,上线一般要开启

#keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位是秒

#gzip on; #开启gzip压缩输出(无论是请求还是响应,网络都是以IO流的形式输出), 一般要开启,开启后,会自动去掉空格等,速度更快

#一个http中,可以有若干个server
server {
listen 80; #配置监听端口
server_name localhost; #配置服务名,如域名、IP等。不同的server,listen+server_name不能完全一样

#charset koi8-r; #配置字符集

#access_log logs/host.access.log main; #配置本虚拟主机的访问日志(即:该server)

#默认的匹配斜杠/的请求,当访问路径中有斜杠/,会被该location匹配到并进行处理。斜杠/后面可以跟项目名称,表示下面root配置的根目录下的文件夹,首页文件需要放在该文件夹下,访问地址也要加该名称
location / {
root html; #root是配置服务器的默认网站根目录位置,默认为nginx安装主目录标的html目录(即本地磁盘路径,如:root www/webapps,即为nginx根目录下的www/webapps路径
index index.html index.htm; #配置首页文件的名称
}

#error_page 404 /404.html; #配置404错误文件

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; #配置50x错误文件
#精确匹配
location = /50x.html {
root html; #50x.html目录
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

posted @ 2022-04-19 09:43  楠楠之歌  阅读(276)  评论(0编辑  收藏  举报