Nginx常用配置
#进程守护者:usernginx;
#错误日志
error_loglogs/error.log;
#pid进程信息:
pid logs/nginx.pid;
#worker进程数:
worker_processes1;
#每进程处理连接数:
worker_connections1024;
#主配置区域结构:
http{
#mime文件类型
include mime.types;
#默认为附件类型
default_typeapplication/octet-stream;
#访问日志格式
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#开启访问日志
#access_loglogs/access.logmain;
#延迟发送,优化带宽阻塞
sendfile on;
#tcp_nopush on;
#等待超时时间
#keepalive_timeout0;
keepalive_timeout65;
#网页压缩传输
gzipon;
#第一台http虚拟主机配置
server{
#端口号
listen 80;
#网站域名
server_namelocalhost;
#web字符集
#charset koi8-r;
#访问日志
#access_loglogs/host.access.logmain;
#匹配192.168.2.1或192.168.2.1/
location / {
#设置网站根目录
root html;
#设置默认首页
indexindex.php index.html index.htm;
}
#设置404错误页面
#error_page404 /404.html;
#设置50x错误页面
error_page 500 502 503 504/50x.html;
location = /50x.html {
root html;
}
#访问php文件时直接交给本机apache服务来处理
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
#请求php文件时交给php-fpm处理
location ~ \.php$ {
fastcgi_indexindex.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
拒绝所有人访问.htaccess文件
location ~ /\.ht {
denyall;
}
}
#第二台http虚拟主机配置
server {
listen 8000;
listen somename:8080;
server_namesomenamealiasanother.alias;
location / {
root html;
indexindex.html index.htm;
}
}
#配置https虚拟主机
server {
listen 443 ssl;
server_namelocalhost;
ssl_certificate cert.pem;
ssl_certificate_keycert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout5m;
ssl_ciphersHIGH:!aNULL:!MD5;
ssl_prefer_server_cipherson;
location / {
root html;
indexindex.html index.htm;
}
}
}
页:
[1]