查找nginx配置文件路径
nginx -t(检查配置文件是否有语法错误,并获取nginx配置文件路径)
cd usr/local/nginx/conf/
#user nobody;
#指定可以运行nginx的用户和用户组,window下不生效,会警告
worker_processes 1;
#nginx工作进程
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#全局的日志文件存放点
#pid logs/nginx.pid;
#pid文件存放点
events {
worker_connections 1024;
#单个进程最大连接数(最大连接数=进程数+连接数)
#accept_mutex on
#accept_mutex默认开启(以串行方式处理连接,利于性能优化),关闭会导致多个连接随机命中一个连接
}
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;
#启用sendfile()系统调用来替换read()和write()调用,减少系统上下文切换从而提高性能
#tcp_nopush on;
keepalive_timeout 65;
#保持连接的时间
#gzip on;
#开启文件压缩,提高性能
server {
#server模块相当于虚拟主机
listen 80;
#指定连接地址(可以是端口号、ip:端口号、ip、*)
server_name localhost;
#别名
#charset koi8-r;
#编码方式
#access_log logs/host.access.log main;
location / {
#表示访问/下的文件时nginx会到/html下面去找
root html;
index index.html index.htm;
}
#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;
# }
#}
}
}