当前位置: 首页 > news >正文

Nginx基础入门篇-基础配置

目录

Nginx配置文件

Nginx编译参数

Nginx基本配置

创建一个网站


Nginx配置文件

通过 rpm -ql nginx查询
/etc/logrotate.d/nginx #日志轮转
/etc/nginx/nginx.conf #主配置文件
/etc/nginx/conf.d #子配置文件
/etc/nginx/conf.d/default.conf #默认的网站配置文件
/etc/nginx/fastcgi_params #动态网站模块文件-python,php所需的相关变量
/etc/nginx/scgi_params #传递给 SCGI 服务器的标准参数
/etc/nginx/uwsgi_params #传递给 uWSGI 服务器的标准参数
/etc/nginx/koi-utf #字符集,文件编码
/etc/nginx/win-utf #Nginx 为 Windows 系统提供的字符编码配置文件
/etc/nginx/koi-win #是一个字符集映射文件,可以在KOI8-R和Windows-1251编码之间进行转换
/etc/nginx/mime.types #网站文件类型和相关处理程序
/usr/lib64/nginx/modules #第三方模块
/usr/lib/systemd/system/nginx.service #脚本服务
/usr/sbin/nginx  #主程序
/usr/sbin/nginx-debug #nginx的调试程序
/usr/share/doc/nginx-1.12.1 #文档
/usr/share/doc/nginx-1.12.1/COPYRIGHT #包含基于标准Nginx发行版
/usr/share/man/man8/nginx.8.gz #man手册
/usr/share/nginx #nginx在许多Linux发行版上用于存储静态文件、文档和其他共享资源的标准位置
/usr/share/nginx/html #许多Linux发行版上nginx的默认web根目录包含Nginx默认提供给客户端的静态文件
/usr/share/nginx/html/50x.html #nginx为5xx服务器错误提供的默认错误页面
/usr/share/nginx/html/index.html #默认主页
/var/cache/nginx #nginx在使用代理缓存或其他缓存功能时存储缓存内容的地方
/var/log/nginx #nginx的日志文件夹
/usr/lib64/nginx #nginx模块目录

Nginx编译参数

通过nginx -V查看
configure arguments: #配置参数./configure --help查询帮助
--prefix=/etc/nginx #安装路径
--sbin-path=/usr/sbin/nginx #程序文件
--modules-path=/usr/lib64/nginx/modules #模块路径
--conf-path=/etc/nginx/nginx.conf #主配置文件
--error-log-path=/var/log/nginx/error.log #错误日志
--http-log-path=/var/log/nginx/access.log #访问日志
--pid-path=/var/run/nginx.pid #程序ID
--lock-path=/run/lock/subsys/nginx #锁路径,防止重复安装nginx
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body #缓存
--http-proxy-temp-path=/var/cache/nginx/proxy_temp #代理缓存
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp #php缓存
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp #python缓存
--http-scgi-temp-path=/var/cache/nginx/scgi_temp  #指定nginx为scgi(简单通用网关接口)请求存储临时文件的目录。
--with-compat #启用动态模块兼容性
--user=nginx #用户
--group=nginx #组
--with-file-aio #是异步非阻塞,大大提高性能
--with-threads #多线程模块
--with-http_addition_module #响应之前或者之后追加文本内容
--with-http_auth_request_module #认证模块
--with-http_dav_module #添加上传put,delete,mkcol:创建集合,copy和move方法,默认关闭
--with-http_flv_module #nginx添加mp4,flv视频支持模块
--with-http_gunzip_module #压缩模块
--with-http_gzip_static_module #启用Nginx的gzip静态模块,该模块允许提供预压缩文件(.gz文件),而不是动态压缩文件。
--with-http_mp4_module #多媒体模块
--with-http_random_index_module #nginx显示随即首页模块
--with-http_realip_module #nginx获取真实ip模板
--with-http_secure_link_module #nginx安全下载模块
--with-http_slice_module #nginx中文文档
--with-http_ssl_module #安全模块
--with-http_stub_status_module #访问状态
--with-http_sub_module #nginx替换网站响应内容
--with-http_v2_module #可在Nginx中启用http/2支持。
--with-mail #邮件客户端
--with-mail_ssl_module  #Nginx的邮件代理模块启用ssl/TLS支持
--with-stream #负载均衡模块
--with-stream_realip_module #启用Nginx的stream Real IP模块。此模块允许Nginx修改流(TCP/UDP)代理连接中的客户端IP地址
--with-stream_ssl_module #Nginx中的TCP和UDP流连接启用ssl/TLS终止
--with-stream_ssl_preread_module #启用Nginx的stream ssl预读模块。该模块允许Nginx从SSL/TLS握手中提取信息(如服务器名称指示-SNI),而无需解密流量,从而为加密流启用基于内容的路由。

Nginx基本配置

主配置文件/etc/nginx/nginx.conf内容说明

CoreModule核心模块(进程数):配置影响nginx全局的指令。般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。

EventsModule事件驱动模块(工作模式):配置影响nginx服务器或与用户的网络连接,有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。

HttpCoreModule http内核模块(文档程序类型,配置文件等)

http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。

server块:配置虚拟主机的相关参数,一个http中可以有多个server。

location块:配置请求的路由,以及各种页面的处理情况

user  nginx; #运行nginx程序的独立账号
worker_processes  auto; #启动的worker进程数量(CPU数量一致或auto)error_log  /var/log/nginx/error.log notice; #错误日志存放位置
pid        /run/nginx.pid; #nginx的pidevents { #事件use epoll; #事件驱动模块epollworker_connections  1024; #每个worker进程允许处理的最大连接数
}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; #包含子配置文件夹
}

默认虚拟机配置文件

server { #默认网站配置文件listen       80; #监听端口server_name  localhost; #FQDN#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$ { #匹配所有以.php结尾的请求
#    proxy_pass   http://127.0.0.1; #代理#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #动态网站设置##location ~ \.php$ { #匹配所有以.php结尾的请求#    root           html; #设置PHP文件的根目录#    fastcgi_pass   127.0.0.1:9000; #指定PHP-FPM服务器的地址#    fastcgi_index  index.php; #设置默认的索引文件名称#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; #告诉PHP-FPM要执行哪个PHP文件#    include        fastcgi_params; #引入标准的FastCGI参数文件#}# deny access to .htaccess files, if Apache's document root #访问控制部分# concurs with nginx's one##location ~ /\.ht { #匹配所有包含.ht的请求路径#    deny  all; #拒绝所有访问请求#}
}Type  :qa  and press <Enter> to exit Vim                              44,0-1       底端

创建一个网站

vim /etc/nginx/conf.d/ts.conf server     { #虚拟主机
listen    80; #监听端口
server_name    ts.com; #服务器名称
location / { #网站目录设置
root    /ts; #网站主目录在本地的路径
index     index.html ; #主页文件名
}
}
mkdir   /ts #创建存放网站目录的文件夹
echo   11111   >  /ts/index.htmlsystemctl restart nginx#做域名解析和访问

http{} 是整个服务器,所有网站的设置。

server{}是某一个网站的设置。

location{} 是某一个页面的设置。

http://www.dtcms.com/a/540998.html

相关文章:

  • 雅可比SVD算法:高精度矩阵分解的经典方法
  • 在 Python 中测试中assert断言和 if分支的区别
  • 【题解】洛谷 P1169 [ZJOI2007] 棋盘制作 [思维 + dp]
  • 音频限幅器D2761使用手册
  • 网站金融模版wordpress轮播代码
  • 【工具推荐】电脑手机多端互通协作实用
  • 一般网站的跳出率dede做双语网站
  • 自己制作的网站如何发布建筑设计公司经营范围有哪些
  • 51c大模型~合集39
  • 操作【GM3568JHF】FPGA+ARM异构开发板 使用指南:串口
  • 【牛客CM11】链表分割
  • .NET 对象转Json的方式
  • 广西住建局官方网站大数据营销的应用领域
  • Linux ioctl 深度剖析:从原理到实践
  • 网站备案流程解答做最漂亮的网站
  • LED驱动电路(三)
  • Keil工程编译垃圾清理
  • 同城跑腿APP源码开发技术全景:即时订单、骑手定位与路线优化算法
  • 【数据工程】15. Stream Query Processing
  • 鄂州网站设计效果wordpress comment_form_after
  • 爱网站关键词查询工具潍坊营销网站
  • java程序生成pdf或wod乱码
  • 做网站和游戏是如何赚钱crm系统开发
  • 网页pdf下载攻略--以混元上传的pdf为例
  • AI在处理扫描版PDF时准确率低,如何提升?
  • 网站做成软件免费wordpress 首页制作
  • 所有网站打不开深圳做app网站的公司名称
  • centos 7 redhat7 升级内核 升级内核到5.4版本 202510试过可以成功
  • 什么是TC8?
  • EtherNet/IP转ProfiNet智能网关配置指南:西门子1500PLC与多台机器人通讯