Nginx出现403 Forbidden、404 Not Found错误的解决方案

ops/2024/9/23 8:14:28/

一、Docker创建Nginx容器

Docker命令

docker run -d \--name nginx \-p 80:80 \-v /root/nginx/dist:/usr/share/nginx/html \-v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \nginx

nginx.conf

nginx">worker_processes  1;events {worker_connections  1024;
}http {include       mime.types;default_type  application/json;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root /root/nginx/dist;index index.html;}error_page   500 502 503 504  /50x.html;location = /50x.html {root /root/nginx/dist;}}
}

二、403 Forbidden

2.1 问题分析

默认情况下,使用Docker创建的Nginx容器默认会以nginx用户运行,而不是root用户

2.2 解决方案

在Nginx配置文件中,指定Nginx以root用户运行

nginx">user root;		# 此配置应添加到Nginx配置文件的开头 
nginx">user root;		# 此配置应添加到Nginx配置文件的开头 worker_processes  1;events {worker_connections  1024;
}http {include       mime.types;default_type  application/json;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root /root/nginx/dist;index index.html;}error_page   500 502 503 504  /50x.html;location = /50x.html {root /root/nginx/dist;}}
}

三、404 Not Found

3.1 问题分析

Nginx配置文件中location /块的root指令,错误地指向了主机上的/root/nginx/dist目录,而不是容器内的/usr/share/nginx/html目录

3.2 解决方案

修改Nginx配置文件中location /块的root指令,确保其指向容器内的/usr/share/nginx/html目录

nginx">user root;worker_processes  1;events {worker_connections  1024;
}http {include       mime.types;default_type  application/json;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root /usr/share/nginx/html;index index.html;}error_page   500 502 503 504  /50x.html;location = /50x.html {root /root/nginx/dist;}}
}

http://www.ppmy.cn/ops/4613.html

相关文章

SQL序列

序列 SEQUENCE 序列是Oracle提供的一组能够自动增长的序号,一般是提供主键值用的。 序列的创建 CREATE SEQUENCE 序列名 ----可以结束了START WITH n ----初始值 n,如果这句话不写,默认是1INC…

【软件设计】

设计原则 单一职责原则Single responsibility principle(SRP) A class should have a single purpose and only one reason to change If a class has more than one responsibility, then the responsibilities becomes coupled SRP is one of the simplest of the principl…

AI推介-大语言模型LLMs论文速览(arXiv方向):2024.04.10-2024.04.15

文章目录~ 1.Unveiling Imitation Learning: Exploring the Impact of Data Falsity to Large Language Model2.Are Large Language Models Reliable Argument Quality Annotators?3.LoRAP: Transformer Sub-Layers Deserve Differentiated Structured Compression for Large …

计算机视觉动作识别——YOWO用于实时时空动作定位与识别的算法解析

摘要 时空动作定位要求将两种信息源整合到设计的架构中:(1) 来自先前帧的时间信息和(2) 来自关键帧的空间信息。当前的最先进方法通常使用单独的网络提取这些信息,并使用额外的机制进行融合以获得检测结果。YOWO是一个用于视频流中实时时空动作定位的统…

探索边缘计算:技术的新疆界

探索边缘计算:技术的新疆界 在当今迅速发展的数字化时代,云计算作为数据处理的主力军已广泛应用。但是,随着物联网(IoT)设备的急剧增加和数据生成速率的加快,云计算面临着种种挑战。边缘计算因此诞生&…

区块链技术的应用场景和优势

区块链技术的应用场景和优势 区块链技术的应用场景和优势是多样的 金融领域:区块链技术可以用于实现去中心化的数字货币,如比特币,以及进行跨境支付和智能合约等金融交易。它可以提高交易速度、降低成本、增加安全性和透明度。 物联网&…

使用UDP实现TCP的功能,会带来什么好处?

比较孤陋寡闻,只知道QUIC TCPQUIC握手延迟TCP需要三次握手TLS握手三次握手TLS握手放在一起,实现0RTT头阻塞问题TCP丢失保文,会影响所有的应用数据包基于UDP封装传输层Stream,Stream内部保序,Stream之间不存在相互影响…

基于FVCOM模型的三维水动力、水交换、溢油物质扩散及输运数值模拟

近岸海域水交换是海洋环境科学研究的一个基本命题, 污染物通过对流输运和稀释扩散等物理过程与周围水体混合, 与外海水交换, 浓度降低, 水质得到改善。交换不畅的水体, 由于污染物的持续累积, 往往会形成诸如富营养化等问题。本文基于FVCOM的水动力模块和染色剂模块&#xff0c…