user www www; #制定nginx 运行的用户名和用户组 worker_processes 4; #nginx 进程数 建议设置成 CPU几核 这里设置成几#error_log logs/error.log; 全局错误日志类型 【debug| info|notice | warn| error|alert|crit 】级别从低到高 #error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid; nginx 进程文件 events { #参考事件模型 worker_connections 1024; #单个进程最大连接数 最大连接数 = 连接数* 进程数 根据硬件调整 只要别让 cpu 100% keepalive_timeout 65; #连接超时时间 }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; #开启高效文件传输模式 off 是关闭 #tcp_nopush on; #是否允许 使用socket TCP_CORK 选项 #keepalive_timeout 0; keepalive_timeout 65;#连接超时时间 #gzip on; 开启gzip 压缩 速度更快 server { listen 8080; #监听的端口号 server_name localhost; #www.baidu.com baidu.com #charset koi8-r; #字符集 #access_log logs/host.access.log main; 日志文件 root /data/www; #根路径 location / { #好比grep location / 表示 匹配 用户输入的 www.baidu.com baidu.com 及以这个开头的所有请求 www.baidu.com/index.html baidu.com/123.jpg #root /data/www; index index.php index.html index.htm; #默认首页 } location ~ \.php$ { ~ 区分大小写 ~* 不区分大小写 特殊字符要转义 #root /data/www; #跟目录 fastcgi_pass 127.0.0.1:9000; nginx 跟 php之间 交流通过 9000端口 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #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; } # 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; # } #} include /usr/local/nginx/conf/vhost/*.conf;}借鉴lnmp https 安装 步骤 lnmp ssl add 添加证书
本文详细介绍了Nginx服务器的配置方法,包括设置运行用户、进程数、错误日志级别等基本配置,以及如何配置HTTP模块来实现高效文件传输、GZIP压缩等功能。此外,还提供了虚拟主机和HTTPS服务器的配置示例。
1680

被折叠的 条评论
为什么被折叠?



