Nginx的简单配置(可直接使用)

#定义Nginx运行的用户和用户组
#user nobody nobody;
#nginx进程数,建议设置为等于CPU总核心数
worker_processes 2;

#error_log logs/error.log;
# 全局错误日志定义类型
error_log logs/error.log notice;
#error_log logs/error.log info;
#进程文件
pid logs/nginx.pid;


events {
#单个进程最大连接数
worker_connections 1024;
}

#设定http服务器
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;
#服务注册(每一个server都是一个单独的服务)
server {
#当前启动服务的端口(监听)
listen 8089;
#当前服务的服务名称
server_name lsdn_nginx;
#index index.html index.htm;
root html/dist/;
#
charset utf-8;

access_log logs/host.access.log main;
#当前服务的默认访问地址
location / {
#当前服务默认访问页面
index index.html index.htm;
#当前服务的静态资源地址
root html/dist/;
}

#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;
}
#查看nginx状态
#location /nginxStatus {

#stub_status on;

#access_log on;

#auth_basic "NginxStatus";

#auth_basic_user_file confpasswd;

#htpasswd文件的内容可以用apache提供的htpasswd工具来产生。
#}
}

原文地址:https://www.cnblogs.com/Sora-L/p/12780158.html