linux nginx root目录,详解nginx.conf 中 root 目录设置问题
在配置 nginx.conf 总会遇到一些问题,下面列举一些常见的问题并说明如何解决
1、相对路径的问题
例如配置文件中 location 设置
location ~ .php${
root html
}
location 中root所指向的html是一个相对路径,相对的是这个配置文件的路径,假设此配置文件的位置是/etc/nginx/conf.d,那么这个html的绝对路径就是/etc/nginx/conf.d/html。因此为避免出现不必要的麻烦,在配置root路径的过程中最好用绝对路径。
2、路径的继承问题
2.1 第一种情况
假如server 中声明:
root /usr/share;
且 location 中声明:
location /{
root /usr/html/www
}
此时会优先使用 location 中的路径
2.2 第二种情况
假如 location 中未对root路径进行声明:
location /app {
}
则默认使用 location 外的 root 声明的路径
3、首页的设置问题
假如我们在声明server 中声明:
index index.html index.php
那么我们此时请求 / 就会在内部重定向到 url/index.php 或者 url/index.html
然后再由相关的location 进行匹配 之后再进行解析
nginx.conf文件的详解
官网对各个模块参数配置的解释说明网址: Nginx中文文档
##代码块中的events、http、server、location、upstream等都是块配置项##
##块配置项可以嵌套。内层块直接继承外层快,例如:server块里的任意配置都是基于http块里的已有配置的##
##Nginx worker进程运行的用户及用户组
#语法:user username[groupname] 默认:user nobody nobody
#user用于设置master进程启动后,fork出的worker进程运行在那个用户和用户组下。当按照"user username;"设置时,用户组名与用户名相同。
#若用户在configure命令执行时,使用了参数--user=usergroup 和 --group=groupname,此时nginx.conf将使用参数中指定的用户和用户组。
#user nobody;
##Nginx worker进程个数:其数量直接影响性能。
#每个worker进程都是单线程的进程,他们会调用各个模块以实现多种多样的功能。如果这些模块不会出现阻塞式的调用,那么,有多少CPU内核就应该配置多少个进程,反之,有可能出现阻塞式调用,那么,需要配置稍多一些的worker进程。
worker_processes 1;
##ssl硬件加速。
#用户可以用OpneSSL提供的命令来查看是否有ssl硬件加速设备:openssl engine -t
#ssl_engine device;
##守护进程(daemon)。是脱离终端在后台允许的进程。它脱离终端是为了避免进程执行过程中的信息在任何终端上显示。这样一来,进程也不会被任何终端所产生的信息所打断。##
##关闭守护进程的模式,之所以提供这种模式,是为了放便跟踪调试nginx,毕竟用gdb调试进程时最繁琐的就是如何继续跟进fork出的子进程了。##
##如果用off关闭了master_proccess方式,就不会fork出worker子进程来处理请求,而是用master进程自身来处理请求
#daemon off; #查看是否以守护进程的方式运行Nginx 默认是on
#master_process off; #是否以master/worker方式工作 默认是on
##error日志的设置#
#语法: error_log /path/file level;
#默认: error_log / log/error.log error;
#当path/file 的值为 /dev/null时,这样就不会输出任何日志了,这也是关闭error日志的唯一手段;
#leve的取值范围是debug、info、notice、warn、error、crit、alert、emerg从左至右级别依次增大。
#当level的级别为error时,error、crit、alert、emerg级别的日志就都会输出。大于等于该级别会输出,小于该级别的不会输出。
#如果设定的日志级别是debug,则会输出所有的日志,这一数据量会很大,需要预先确保/path/file所在的磁盘有足够的磁盘空间。级别设定到debug,必须在configure时加入 --with-debug配置项。
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
##pid文件(master进程ID的pid文件存放路径)的路径
#pid logs/nginx.pid;
events {
#仅对指定的客户端输出debug级别的日志: 语法:debug_connection[IP|CIDR]
#这个设置项实际上属于事件类配置,因此必须放在events{……}中才会生效。它的值可以是IP地址或者是CIRD地址。
#debug_connection 10.224.66.14; #或是debug_connection 10.224.57.0/24
#这样,仅仅以上IP地址的请求才会输出debug级别的日志,其他请求仍然沿用error_log中配置的日志级别。
#注意:在使用debug_connection前,需确保在执行configure时已经加入了--with-debug参数,否则不会生效。
worker_connections 1024;
}
##核心转储(coredump):在Linux系统中,当进程发生错误或收到信号而终止时,系统会将进程执行时的内存内容(核心映像)写入一个文件(core文件),以作为调试只用,这就是所谓的核心转储(coredump).
http {
##嵌入其他配置文件 语法:include /path/file
#参数既可以是绝对路径也可以是相对路径(相对于Nginx的配置目录,即nginx.conf所在的目录)
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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
##listen监听的端口
#语法:listen address:port [ default(deprecated in 0.8.21) | default_server | [ backlog=num | rcvbuf=size | sndbuf=size | accept_filter=filter | deferred | bind | ssl ] ]
#default_server: 如果没有设置这个参数,那么将会以在nginx.conf中找到的第一个server块作为默认server块
listen 8080;
#主机名称:其后可以跟多个主机名称,开始处理一个HTTP请求时,nginx会取出header头中的Host,与每个server中的server_name进行匹配,以此决定到底由那一个server来处理这个请求。有可能一个Host与多个server块中的server_name都匹配,这时会根据匹配优先级来选择实际处理的server块。server_name与Host的匹配优先级见文末。
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
##location 语法: location [=|~|~*|^~] /uri/ { ... }
# location的使用实例见文末。
#注意:location时有顺序的,当一个请求有可能匹配多个location时,实际上这个请求会被第一个location处理。
location / {
proxy_pass http://192.168.1.60;
}
#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 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
linux nginx root目录,详解nginx.conf 中 root 目录设置问题相关推荐
- 安装linux子系统报错,详解win10电脑中安装linux子系统出现错误0x80070057方法
现在很多的小伙伴在安装系统的时候都是选择安装双系统的操作的,那其实可以根据需求安装 Win10的系统还有linux系统的是很常见的开发用户的程序的选择,win10电脑就内置有linux子系统的,安装出 ...
- Nginx错误日志详解
Nginx错误日志详解 Nginx软件会把自身运行的故障信息及用户访问的日志信息记录到指定的日志文件里 Nginx错误日志信息介绍 Nginx的错误信息是调试Nginx服务的重要手段,属于核心功能模块 ...
- linux:命令su、exit、sudo登入、退出用户、临时root权限详解。
linux:命令su.exit.sudo登入.退出用户.临时root权限详解. 简单了解root用户: su和exit: sudo: sudo 使用时需要输入itheima的密码.输对了也不能使 ...
- Linux的SOCKET编程详解
Linux的SOCKET编程详解 一. 网络中进程之间如何通信 进程通信的概念最初来源于单机系统.由于每个进程都在自己的地址范围内运行,为保证两个相互通信的进 程之间既互不干扰又协调一致工作,操作系统 ...
- Linux的SOCKET编程详解——非常叼
http://blog.csdn.net/hguisu/article/details/7445768/ 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Linux的SOCKE ...
- Server.MapPath()目录详解
最近在做相关的开发,碰到了Server.MapPath(),顺便来温习一下 Server.MapPath()获取网站的目录详解 ./当前目录 /网站主目录 ../上层目录 ~/网站虚拟目录 如果当前 ...
- linux下nginx启动不了,详解Nginx启动失败的几种错误处理
使用Nginx做Web服务器过程中,碰到过以下几个问题: 1.nginx启动失败 启动nginx失败,报错信息如下: Starting nginx: nginx: [emerg] bind() to ...
- 详解 nginx 配置文件及构建 web 虚拟主机
详解 nginx 主配置文件.添加服务及构建 web 虚拟主机 一.添加为系统服务 1.方法一 2.方法二 二.nginx 主配置文件 nginx.conf 1.全局配置 2.I/O 事件配置 3.H ...
- Nginx的配置详解
人无再少年,花有重开日--风城玫瑰 德里克·罗斯 Nginx是一款轻量级的HTTP服务器,采用事件驱动的异步非阻塞处理方式框架,这让其具有极好的IO性能,时常用于服务端的反向代理和负载均衡. Ngin ...
最新文章
- IEEE技术领域大奖公布:ML先驱上榜,大陆唯一获奖学者来自清华
- 主成分分析(PCA)matlab代码实现
- Embedding在腾讯应用宝的推荐实践
- Postman发送请求时带上登录信息
- webgis 行政图报错_WebGIS 地图 示例源码下载
- 【数据库系统】元数据
- jQuery图片懒加载示例(滚动函数再加载)
- oracle 由32位迁移到64位的问题
- Python实现图片转pdf
- 使用Python做饼图
- Windows Office 365 Pro Plus安装
- 人脸识别ROC曲线绘制1--生成人脸feature文本
- 【Games104】 如果构建游戏世界
- Unity3D 车流线
- 马斯克疯狂理念在中国落地?国产高速飞行列车即将登场
- 麻将判断几步入听算法
- Go语言的反射三定律
- C1任务1:进制转换 学习与技巧总结
- MES是如何进行物料BOM管理的?
- 使用AlarmManager服务设置闹钟