Nginx 403 forbidden

2024-02-21 04:36
文章标签 nginx forbidden 403

本文主要是介绍Nginx 403 forbidden,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、没有权限问题

         Linux系统中如果Nginx没有web目录的操作权限,也会出现403错误。解决办法:修改web目录的读写权限,或者是把Nginx的启动用户改成目录的所属用户,重启Nginx即可解决。(windows 下则用管理员启动nginx即可)。

 chmod -R 777 /datachmod -R 777 /data/www/

2、由于Nginx启动用户和Nginx工作用户不一致所致

Linux 查看Nginx的启动用户,发现是nobody,而为是用root启动的(windows一般不存在)

# 查看Nginx的运行进程
ps aux | grep nginx

如下图:

 将nginx.config的user改为和启动用户一致。

vim ./nginx.config

3、部分连接访问出现403错误

Nginx 配置服务转发,部分接口出现403错误,我只是做服务器请求地址转发所以根本不存在跨域,猜想是NGINX将请求信息改变了导致无法正常访问,F12查看错误的请求接口中不存在 Content-Type:application/x-www-form-urlencoded,由于某些请求没有用form-data jquery默认就没有Content-Type, Nginx代理修改了你的request-header,修改配置如下

# nginx代理配置
location /cbda-module-common-authority {#不更改请求头信息,其他多余参数全部去掉proxy_set_header Host $http_host; #nginx1.20.1版本可用此配置  #proxy_set_header Host $host; #如果是nginx1.18.0使用proxy_pass http://gatewayservers;
}

4、完整配置如下


user  root; #设置用户
worker_processes  4; # 设置进程数
worker_cpu_affinity auto; #设置进程自动绑定cpu
worker_rlimit_nofile 65535; #设置访问文件的句柄数#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;events {worker_connections  10240;multi_accept on;use epoll;
}http {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  /soft/service/nginx_1.18.0/nginx-1.18.0-install/logs/access.log  main;sendfile        on;tcp_nopush     on;keepalive_timeout  65;tcp_nodelay on;open_file_cache max=102400 inactive=20s;open_file_cache_valid 30s;open_file_cache_min_uses 1;client_header_timeout 30;client_body_timeout 30;reset_timedout_connection on;send_timeout 30;server_tokens off;client_header_buffer_size 1m;large_client_header_buffers 4 1m;client_body_buffer_size 300m;client_body_temp_path /usr/local/service/nginx-1.20.1/client_body_temp;#add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';gzip on;   #表示开启压缩功能gzip_min_length 2k;  #表示允许压缩的页面最小字节数,页面字节数从header头的Content-Length中获取,默认值为0,表示不管页面多大都进行压缩,设置建议设大于1k。如果小于1k可能会越压越大。gzip_buffers 4 5m; #压缩缓存区大小gzip_http_version 1.1; #压缩版本gzip_comp_level 6; #压缩比率,一般选择4-6,为了性能gzip_typs text/css text/xml application/javascript; #指>定压缩的类型 gzip_vary on; #vary header支持;gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript  application/xml  application/x-httpd-php image/jpeg image/gif image/png image/icon image/jpg;gzip_vary on; #varyheader支持,改选项可以让前端的缓存服务器缓存经过GZIP压缩的页面,例如用Squid缓存经过nginx压缩的数据。upstream gatewayservers {server 192.168.66.142:30858;}server {listen       30857;server_name  localhost;charset utf-8;#access_log  /soft/service/nginx_1.18.0/nginx-1.18.0-install/logs/host.access.log  main;location / {root   /usr/local/service/issue-management-1.0/cbdacim-vue-ui/dist;index  index.html index.htm;try_files $uri $uri/ /index.html;}location /cbda-module-common-authority {proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Host $host;proxy_set_header X-Forwarded-Server $host;proxy_set_header Host $http_host;proxy_set_header accept-encodeing 'gzip, deflate';#proxy_set_header content-type 'application/json';proxy_set_header X-Real-IP $remote_addr;proxy_set_header authorization $http_authorization;proxy_set_header accept '*/*';proxy_set_header x-bce-date $http_x_bce_date;proxy_connect_timeout 300;proxy_send_timeout 300;proxy_read_timeout 300;client_max_body_size	300m;proxy_pass http://gatewayservers;}#静态资源缓存过期设置#location ~* \.(ico|jpeg|gif|png|bmp|swf|flv)$ {#expires 30d;  #过期时间为30天#log_not_found off;#access_log off;#}#location ~* \.(js|css)$ {#expires 7d;#log_not_found off;#access_log off;#}#error_page  404              /404.html;# redirect server error pages to the static page /50x.htmlerror_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}# 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;#    }#}}

这篇关于Nginx 403 forbidden的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/730584

相关文章

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

Windows的CMD窗口如何查看并杀死nginx进程

《Windows的CMD窗口如何查看并杀死nginx进程》:本文主要介绍Windows的CMD窗口如何查看并杀死nginx进程问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Windows的CMD窗口查看并杀死nginx进程开启nginx查看nginx进程停止nginx服务

Nginx Location映射规则总结归纳与最佳实践

《NginxLocation映射规则总结归纳与最佳实践》Nginx的location指令是配置请求路由的核心机制,其匹配规则直接影响请求的处理流程,下面给大家介绍NginxLocation映射规则... 目录一、Location匹配规则与优先级1. 匹配模式2. 优先级顺序3. 匹配示例二、Proxy_pa

Windows 系统下 Nginx 的配置步骤详解

《Windows系统下Nginx的配置步骤详解》Nginx是一款功能强大的软件,在互联网领域有广泛应用,简单来说,它就像一个聪明的交通指挥员,能让网站运行得更高效、更稳定,:本文主要介绍W... 目录一、为什么要用 Nginx二、Windows 系统下 Nginx 的配置步骤1. 下载 Nginx2. 解压

Nginx 413修改上传文件大小限制的方法详解

《Nginx413修改上传文件大小限制的方法详解》在使用Nginx作为Web服务器时,有时会遇到客户端尝试上传大文件时返回​​413RequestEntityTooLarge​​... 目录1. 理解 ​​413 Request Entity Too Large​​ 错误2. 修改 Nginx 配置2.1

Web技术与Nginx网站环境部署教程

《Web技术与Nginx网站环境部署教程》:本文主要介绍Web技术与Nginx网站环境部署教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Web基础1.域名系统DNS2.Hosts文件3.DNS4.域名注册二.网页与html1.网页概述2.HTML概述3.

NGINX 配置内网访问的实现步骤

《NGINX配置内网访问的实现步骤》本文主要介绍了NGINX配置内网访问的实现步骤,Nginx的geo模块限制域名访问权限,仅允许内网/办公室IP访问,具有一定的参考价值,感兴趣的可以了解一下... 目录需求1. geo 模块配置2. 访问控制判断3. 错误页面配置4. 一个完整的配置参考文档需求我们有一

使用Nginx配置文件服务器方式

《使用Nginx配置文件服务器方式》:本文主要介绍使用Nginx配置文件服务器方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 为什么选择 Nginx 作为文件服务器?2. 环境准备3. 配置 Nginx 文件服务器4. 将文件放入服务器目录5. 启动 N

Nginx路由匹配规则及优先级详解

《Nginx路由匹配规则及优先级详解》Nginx作为一个高性能的Web服务器和反向代理服务器,广泛用于负载均衡、请求转发等场景,在配置Nginx时,路由匹配规则是非常重要的概念,本文将详细介绍Ngin... 目录引言一、 Nginx的路由匹配规则概述二、 Nginx的路由匹配规则类型2.1 精确匹配(=)2

Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例

《Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例》本文介绍Nginx+Keepalived实现Web集群高可用负载均衡的部署与测试,涵盖架构设计、环境配置、健康检查、... 目录前言一、架构设计二、环境准备三、案例部署配置 前端 Keepalived配置 前端 Nginx