Nginx的配置与启动
配置文件
$ cat conf/nginx.conf
#设置用户
user nginx;
#工作线程
worker_processes auto;
#error_log logs/error.log;
#设置日志级别
error_log logs/error.log notice;
#error_log logs/error.log info;
#编译时文件安装的目录
pid /var/run/nginx.pid;
#打开最大的文件描述符
worker_rlimit_nofile 65535;
events {
#设置工作模式
use epoll;
#设置最大连接数
worker_connections 65535;
}
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" $scheme $request_filename $args';
access_log logs/access.log main;
server_tokens off;
sendfile on;
#防止网络阻塞
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#优化相关的配置
server_names_hash_bucket_size 128;
client_max_body_size 20m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
#打开压缩
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#虚拟主机的开始
server {
#指定监听端口
listen 80;
#指定ip或者域名
server_name localhost 10.50.34.88;
#指定字体
#charset koi8-r;
charset utf-8;
#指定虚拟主机日志
access_log logs/host.access.log main;
#设置访问根时的回应
location / {
#设置工作目录
root html;
#设置主页
index index.html index.htm;
}
#设置404时的页面 /404.html指的是工作目录下的404.html
error_page 404 /404.html;
#redirect server error pages to the static page /50x.html
#指定5系列状态码时跳转页面
error_page 500 502 503 504 /50x.html;
#设置当访问/50x.html时的操作
location = /50x.html {
#设置当前的工作目录
root html;
}
}
}
测试配置文件
$ sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动
sbin/nginx
测试
本文来自博客园,作者:厚礼蝎,转载请注明原文链接:https://www.cnblogs.com/guangdelw/p/17911319.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
2022-12-18 二进制安装mysql
2022-12-18 yum在线安装mysql
2022-12-18 修改mysql密码规则
2022-12-18 MySQL发行版的选择
2022-12-18 centos7 编译安装mysql
2022-12-18 rsync数据镜像工具