做网站的模板,沈阳,怎么创建自己的免费网址,已收录的网站不好优化最近有好几个地方用到了nginx#xff0c;但是一直还没时间记录下nginx的安装、配置和使用#xff0c;这篇文章可以将这块内容整理出来#xff0c;方便大家一起学习~
安装
安装是相对简单一些的#xff0c;直接使用yum即可。 yum install -y nginx 默认安装位置在/usr/sb…最近有好几个地方用到了nginx但是一直还没时间记录下nginx的安装、配置和使用这篇文章可以将这块内容整理出来方便大家一起学习~
安装
安装是相对简单一些的直接使用yum即可。 yum install -y nginx 默认安装位置在/usr/sbin/nginx这个位置下
也可以通过命令查询 whereis nginx 会有多个输出 配置
配置文件默认在/etc/nginx下主配置文件是nginx.conf 配置内容解读
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx; #默认用户
worker_processes auto; # 工作进程设定auto含义是cpu数量-1
error_log /var/log/nginx/error.log; # 定义错误日志的位置
pid /run/nginx.pid; #设定pid的位置# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; # 加载支持的模块events { #事件worker_connections 1024;
}http { #配置定义的http的信息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; #http请求访问日志的位置sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 4096;include /etc/nginx/mime.types;default_type application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;#扩展配置的路径例如在对应的路径下增加配置文件即可。server {# 默认监听的端口listen 80;listen [::]:80;server_name _;root /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf; #扩展配置的路径error_page 404 /404.html;location /404.html { #错误的默认访问页面}error_page 500 502 503 504 /50x.html;location /50x.html { #错误的默认访问页面}}
worker_processes 指定 Nginx 使用的 worker 进程数量。使用 auto 可以自动根据 CPU 核心数进行调整。events 部分定义了 Nginx 的事件模型相关的设置例如 worker_connections 指定每个 worker 进程可同时处理的连接数。http 部分是配置 HTTP 服务相关的配置项。include mime.types 指定了 MIME 类型的配置文件路径用于解析文件类型。default_type 指定了默认的 MIME 类型。sendfile on 开启了 sendfile 功能可以提高文件传输效率。keepalive_timeout 指定了 keepalive 连接的超时时间。server 定义了一个虚拟主机server block其中 listen 指定了监听的端口和 IP。location / 是一个 location 块指定了请求的 URI 以 / 开头时的处理方式。root 指定了网站文件的根目录。index 指定了默认的主页文件。error_page 定义了一些错误页面的处理方式例如 404 页面和 50x500、502、503、504错误页面。