ngx_http_index_module index指令 ngx_http_core_module http指令 location指令 listen指令 root指令 server指令 server_name指令 Nginx之坑:彻底理解location中的index,配置网站初始页 https://blog.csdn.net/qq_32331073/article/details/81945134
建立静态资源html
为 conf/nginx.conf
http模块中新增server模块nginx
E:\mozq\00store\frxx ├─frxx │ bug.png │ weixin.png
server{ listen 9001; server_name localhost; location / { root E:\mozq\00store\frxx; # root参数不能以斜杠结尾否则报错。 } } # 示例1 成功 http://localhost:9001/weixin.png # 示例2 失败 请求: http://localhost:9001 响应: Request URL: http://localhost:9001/ Request Method: GET Status Code: 403 Forbidden # 示例3 失败 请求: http://localhost:9001/weixin.pn 响应: Request URL: http://localhost:9001/weixin.pn Request Method: GET Status Code: 404 Not Found # 示例4 失败 请求: http://localhost:9002/ 响应: 没法访问此网站。由于9002端口根本没有服务提供者。
server { listen 9001; server_name localhost; location /fr { # root和alias都不能加斜杠,否则报错。上面的/fr不能写成/fr/。 #root D:\00\frxx; # /fr/zhou.html 访问 D:\00\frxx\fr\zhou.html alias D:\00\frxx; # /fr/zhou.html 访问 D:\00\frxx\zhou.html #index chang.html; } }
# location块文档 http://nginx.org/en/docs/http/ngx_http_core_module.html#location
# nginx默认配置 location / { root html; # 指定资源为nginx主目录下的html目录。 index index.html index.htm; # 指定默认首页列表 }
E:\mozq\chengxu\nginx\nginx-1.16.1>nginx -s reload nginx: [emerg] unexpected "}" in E:\mozq\chengxu\nginx\nginx-1.16.1/conf/nginx.conf:40 错误代码:没有以分号结尾 location / { root E:\mozq\00store\frxx } 正确代码:以分号结尾 location / { root E:\mozq\00store\frxx; }
E:\mozq\00store>nginx -s reload nginx: [alert] could not open error log file: CreateFile() "logs/error.log" failed (3: The system cannot find the path specified) 2019/10/29 09:12:42 [notice] 9640#17752: using inherited sockets from "E:\mozq\chengxu\nginx\nginx-1.16.1" 2019/10/29 09:12:42 [emerg] 9640#17752: invalid socket number "E:\mozq\chengxu\nginx\nginx-1.16.1" in NGINX environment variable, ignoring the rest of the variable 2019/10/29 09:12:42 [emerg] 9640#17752: invalid socket number "E:\mozq\chengxu\nginx\nginx-1.16.1" in NGINX environment variable, ignoring 2019/10/29 09:12:42 [emerg] 9640#17752: CreateFile() "E:\mozq\00store/conf/nginx.conf" failed (3: The system cannot find the path specified) E:\mozq\chengxu\nginx\nginx-1.16.1>nginx -s reload nginx: [emerg] invalid socket number "E:\mozq\chengxu\nginx\nginx-1.16.1" in NGINX environment variable, ignoring the rest of the variable nginx: [emerg] invalid socket number "E:\mozq\chengxu\nginx\nginx-1.16.1" in NGINX environment variable, ignoring 缘由: 为nginx设置环境变量为NGINX和其源码中冲突了。 将环境变量名改成NGINX_HOME
C:\Users\1>nginx -s reload -c E:\mozq\chengxu\nginx\nginx-1.16.1\conf\nginx.conf nginx: [alert] could not open error log file: CreateFile() "logs/error.log" failed (3: The system cannot find the path specified) 2019/10/29 13:44:10 [notice] 11572#8380: signal process started 2019/10/29 13:44:10 [error] 11572#8380: CreateFile() "C:\Users\1/logs/nginx.pid" failed (3: The system cannot find the path specified) 缘由: 指定了配置文件,找不到其余文件。使用-p参数指定nginx目录 解决:使用 -p 参数指定 nginx 主目录。 C:\Users\1>nginx -s reload -p E:\mozq\chengxu\nginx\nginx-1.16.1\
E:\mozq\chengxu\nginx\nginx-1.16.1>nginx -s reload nginx: [emerg] unexpected "}" in E:\mozq\chengxu\nginx\nginx-1.16.1/conf/nginx.conf:40 错误代码:root的值以斜杠结尾报错。 server{ listen 9001; server_name localhost; location / { root E:\mozq\00store\frxx\; # root的值以斜杠结尾报错。 } }