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源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析(结合应用场景)

《nginx-t、nginx-sstop和nginx-sreload命令的详细解析(结合应用场景)》本文解析Nginx的-t、-sstop、-sreload命令,分别用于配置语法检... 以下是关于 nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析,结合实际应

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

Nginx 重写与重定向配置方法

《Nginx重写与重定向配置方法》Nginx重写与重定向区别:重写修改路径(客户端无感知),重定向跳转新URL(客户端感知),try_files检查文件/目录存在性,return301直接返回永久重... 目录一.try_files指令二.return指令三.rewrite指令区分重写与重定向重写: 请求

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

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