下载Nginx
解压安装
C:\nginx
)主要配置文件
conf/nginx.conf
conf/vhosts/
目录下(需手动创建)常用配置示例
# 全局配置
worker_processes 1; # 设置工作进程数,通常等于CPU核心数
events {
worker_connections 1024; # 每个工作进程的最大连接数
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 服务器配置
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
启动Nginx
cd C:\nginx
start nginx
或直接运行nginx.exe
停止Nginx
nginx -s stop
nginx -s quit
重新加载配置
nginx -s reload
server {
listen 80;
server_name example.com www.example.com;
location / {
root C:/websites/example;
index index.html index.htm;
}
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate C:/nginx/conf/ssl/example.com.crt;
ssl_certificate_key C:/nginx/conf/ssl/example.com.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;
}
}
端口被占用
netstat -ano | findstr :80
配置文件错误
nginx -t
访问权限问题
性能调优
worker_processes
和worker_connections
希望以上配置指南对您有所帮助。如需更详细的配置说明,可以参考Nginx官方文档或针对特定需求的配置教程。