include
再主配置文件中 /etc/nginx 下 nginx.cong 中 会有 include /etc/nginx/conf.d/*.conf; 这就说明nginx在加载的时候,除了回家在nginx.conf外还会包含 /etc/nginx/conf.d 下的所以以 .conf结尾的文件
配置文件参数说明
1 | user 设置Nginx服务的系统使用用户 |
woker_processes 是nginx工作的进程数,最好和服务器的CPU核数保持一致
nginx.conf文件1
2
3
4
5
6
7
8
9
10
11
12
13http {
include /etc/nginx/mime.types; # content-type
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; # nginx的一个重要功能
#tcp_nopush on;
keepalive_timeout 65; # 超时时间
#gzip on;
include /etc/nginx/conf.d/*.conf; # 包含其他的配置文件
}
/etc/nginx/conf.d下的default.conf文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37server {
listen 80; # 监听端口
server_name localhost; # 域名,主机名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / { # 访问根目录/时,所对应的配置,一个server下,location可以有多个
root /usr/share/nginx/html; # 文件的位置
index index.html index.htm; # 去到上面文件的位置后寻找的文件的,先找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; # 错误页面配置,当出现500 502 503 504这些错误的时候,会去找/50x.html
location = /50x.html { # 为/50x.html 配置localtion
root /usr/share/nginx/html; # 配置50x.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;
#}
}
检查配置
1 | nginx -t -c + 配置文件的路径 |
启动
重启或者启动nginx1
2
3
4systemctl start nginx.service
systemctl restart nginx.service
systemctl reload nginx.service
systemctl stop nginx.service
以指定配置文件的方式,执行某种操作1
nginx -s reload -c + 配置文件