nginx 使用说明(docker)
**************************
相关操作
下载镜像
docker pull nginx
创建容器
docker run -it -d -p 8080:80 --name nginx nginx
**************************
配置文件说明:/etc/nginx/nginx.conf
默认配置
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
user:配置用户、用户组,格式:user user_name [group_name]
worker_process:设置工作进程数(nginx主进程接受客户端请求,然后转交给工作进程处理),格式:worker_process num
pid:设置进程id,格式:pid pid_filename,/var/run/nginx.pid的值为1
error_log:错误日志,格式:error_log log_name [level]
level为日志级别:debug、info、notice、warn、error、crit,默认为error
error_log 关闭:error_log /dev/null
说明:错误日志可在main、http、server、location中设置,不支持自定义日志格式
**********************
events:控制nginx的连接方式
worker_connections:设置nginx的连接数,格式:worker_connections num
**********************
http:http请求相关设置
include:引入配置文件,格式:include file_name
default_type:设置默认文件类型,格式:default_type type_name
log_format:设置日志格式,格式:log_format format_name format_pattern
access_log:设置日志名称、输出格式,格式:access_log log_name format_name
说明:可使用access_log off关闭日志输出
send_file:开启高效传输文件模式,默认为on,格式:send_file on|off
keepalive_timeout:长连接超时时间,格式:keepalive_timeout num
**********************
include /etc/nginx/conf.d/*.conf:引入默认server、location配置 default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/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 /usr/share/nginx/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;
#}
}
server:设置代理的服务器(一个http模块可包含多个location)
listen:设置监听端口,格式:listen port
server_name:监听的服务名,格式:server_name name,name可为ip地址
error_page:设置错误页面,格式:error_page status page_name
location:匹配请求路径
root:请求路径寻找的根目录,格式:root path
index:请求路径对应的索引文件,格式:index index_filename
allow:可以访问,可设置在http、server、location中,格式:allow ip|all
deny:拒绝访问,可是只在http、server、location中,格式:allow ip|all