Nginx-基础配置详解

本文详细介绍了Nginx的基础配置,包括如何配置虚拟主机,如基于域名、IP和端口的方式。同时,文章涵盖了访问日志格式、access_log和error_log的设置,以及日志切割的实现。此外,还讨论了nginx的常用模块如autoindex,状态模块和访问限制模块,如 ngx_http_access_module 和 limit 模块,以及location区域的匹配功能。
摘要由CSDN通过智能技术生成

安装完nginx,会生成基础配置文件nginx.conf

[root@web01 nginx]# cat nginx.conf
user  www; 		#nginx运行的用户
worker_processes  auto; #nginx worker进程数量(处理web请求)
error_log  logs/error.log  info; #指定nginx错误文件日志位置及日志模式
pid        logs/nginx.pid; 	#指定nginx进程文件

events {
   
    worker_connections  1024; 	#每个工作进程并发连接数量
}

#http区域/模块,处理http请求
http {
   		
    include       mime.types; #引用可支持的(媒体)文件类型,include引用或包含其他地方的配置文件
    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; #开启高效传输模式
    keepalive_timeout  65; #超时时间
    gzip  on; #是否压缩
    #nginx 虚拟主机配置
    server {
    
        listen       80; #web服务监听端口
        server_name  game.oldboy.com; #web服务器域名 
        error_page   500 502 503 504  /50x.html;#服务端出错时,提示的错误页面
        location = /50x.html {
   
            root   /app/code;
        }
         #用来匹配请求中URI
        location / {
   
            root   /app/code; #网站站点根目录
            index  index.html index.htm; #网站站点首页
        }        
    }
	 include /etc/nginx/conf.d/*.conf;  #引入其他.conf结尾的配置文件
}

Nginx 各基础配置详解

一、nginx配置虚拟主机

方法:在conf.d配置目录下新.conf文件指定多个server{}区

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值