程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了NGINX - 重定向过多,然后 403 禁止大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决NGINX - 重定向过多,然后 403 禁止?

开发过程中遇到NGINX - 重定向过多,然后 403 禁止的问题如何解决?下面主要结合日常开发的经验,给出你关于NGINX - 重定向过多,然后 403 禁止的解决方法建议,希望对你解决NGINX - 重定向过多,然后 403 禁止有所启发或帮助;

Debian 10.10、Nginx 1.14.2、php8.0 以及基于此 guide

的 Nextcloud 安装

我已按照指南中的说明进行操作,但 SSL、letsencrypt 和 acme 用户部分除外。我省略了这些部分,因为 NPM 处理我所有的证书和反向代理。

web --> 路由器 --> NPM 反向代理 --> Nextcloud 服务器

NPM 在我的其他网站上运行良好,所以我不认为它有问题,一般来说。

我很困惑,所以请对这些回复保持友好。 ;)

root@nextcloud:~# Nginx -t
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful
root@nextcloud:~# ls -alh /var/www/
@R_342_10586@l 16K
drwxr-x---  4 www-data www-data 4.0K Jul 14 12:19 .
drwxr-xr-x 13 root     root     4.0K Jul 13 11:33 ..
drwxr-x---  2 www-data www-data 4.0K Jul 13 11:26 HTML
drwxr-x--- 14 www-data www-data 4.0K Jul 14 12:30 nextcloud

/etc/Nginx/Nginx.conf 文件。 . .

user www-data;
worker_processes auto;
pID /var/run/Nginx.pID;
events {
worker_connections 1024;
multi_accept on; use epoll;
}
http {
server_names_hash_bucket_size 64;
access_log /var/log/Nginx/access.log;
error_log /var/log/Nginx/error.log warn;
set_real_ip_from 127.0.0.1;
#optional,SIE können das eigene subnetz ergänZen,bspw.:
# set_real_ip_from 192.168.2.0/24;
real_ip_header X-ForWARDed-For;
real_ip_recursive on;
include /etc/Nginx/mime.types;
default_type application/octet-stream;
sendfile on;
send_timeout 3600;
tcp_nopush on;
tcp_nodelay on;
open_file_cache max=500 inactive=10m;
open_file_cache_errors on;
keepalive_timeout 65;
reset_timedout_connection on;
server_tokens off;
resolver 127.0.0.53 valID=30s;
resolver_timeout 5s;
include /etc/Nginx/conf.d/*.conf;
}

和/etc/Nginx/conf.d/http.conf

注意:如果我不注释掉“return 301 https://$host$request_uri;”如下所示,我收到一个“重定向过多” 错误。我还注释掉了“letsencrypt”行

upstream php-handler {
server unix:/run/php/php8.0-fpm.sock;
}
server {
Listen 80 default_server;
Listen [::]:80 default_server;
server_name nextcloud.mydomain.vip;
root /var/www;
LOCATIOn ^~ /.well-kNown/acme-chALLENge {
default_type text/plain;
#root /var/www/letsencrypt;
}
LOCATIOn / {
#return 301 https://$host$request_uri;
}
}

和/etc/Nginx/conf.d/nextcloud.conf

我再次注释掉所有的 ssl 行。

“太多重定向”消失了,但现在出现“403 ForbIDden”错误

server {
Listen 443      ssl http2;
Listen [::]:443 ssl http2;
server_name nextcloud.mydomain.vip;
#ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
#ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
#ssl_trusted_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
#ssl_certificate /etc/letsencrypt/rsa-certs/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/rsa-certs/privkey.pem;
#ssl_certificate /etc/letsencrypt/ecc-certs/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/ecc-certs/privkey.pem;
#ssl_trusted_certificate /etc/letsencrypt/ecc-certs/chain.pem;
#ssl_dhparam /etc/ssl/certs/dhparam.pem;
#ssl_session_timeout 1d;
#ssl_session_cache shared:SSL:50m;
#ssl_session_tickets off;
#ssl_protocols TLSv1.3 TLSv1.2;
#ssl_ciphers 'TLS-CHACHA20-poly1305-SHA256:TLS-AES-256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384';
#ssl_ecdh_curve X448:secp521r1:secp384r1;
#ssl_prefer_server_ciphers on;
#ssl_stapling on;
#ssl_stapling_verify on;
clIEnt_max_body_size 5120M;
fastcgi_buffers 64 4K;
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxIEd expired no-cache no-store private no_last_modifIEd no_etag auth;
gzip_types application/atom+xml application/JavaScript application/Json application/ld+Json application/manifest+Json application/RSS+xml application/vnd.geo+Json application/vnd.ms-Fontobject application/x-Font-ttf application/x-web-app-manifest+Json application/xhtml+xml application/xml Font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/CSS text/plain text/vcard text/vnd.rim.LOCATIOn.xloc text/vtt text/x-component text/x-cross-domain-policy;
add_header Strict-Transport-Security            "max-age=15768000; includeSubDomains; preload;" always;
add_header Permissions-Policy                   "interest-cohort=()";
add_header Referrer-Policy                      "no-referrer"   always;
add_header X-Content-Type-Options               "nosniff"       always;
add_header X-Download-Options                   "noopen"        always;
add_header x-frame-options                      "SAMEORIGIN"    always;
add_header X-Permitted-Cross-Domain-PolicIEs    "none"          always;
add_header X-Robots-Tag                         "none"          always;
add_header X-XSS-Protection                     "1; mode=block" always;
fastcgi_hIDe_header X-Powered-By;
fastcgi_read_timeout 3600;
fastcgi_send_timeout 3600;
fastcgi_connect_timeout 3600;
root /var/www/nextcloud;
index index.php index.HTML /index.php$request_uri;
expires 1m;
LOCATIOn = / {
if ( $http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/$is_args$args;
}
}
LOCATIOn = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
LOCATIOn ^~ /apps/rainloop/app/data {
deny all;
}
LOCATIOn ^~ /.well-kNown {
LOCATIOn = /.well-kNown/carddav     { return 301 /remote.php/dav/; }
LOCATIOn = /.well-kNown/caldav      { return 301 /remote.php/dav/; }
LOCATIOn ^~ /.well-kNown            { return 301 /index.php/$uri; }
try_files $uri $uri/ =404;
}
LOCATIOn ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
LOCATIOn ~ ^/(?:\.|autotest|occ|issue|indIE|db_|consolE)                { return 404; }
LOCATIOn ~ \.php(?:$|/) {
rewrite ^/(?!index|remote|public|cron|core\/AJAX\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provIDer\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_filename $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param httpS on;
fastcgi_param modheadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_requesT_Buffering off;
}
LOCATIOn ~ \.(?:CSS|Js|svg|gif)$ {
try_files $uri /index.php$request_uri;
expires 6M;
access_log off;
}
LOCATIOn ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d;
access_log off;
}
LOCATIOn / {
try_files $uri $uri/ /index.php$request_uri;
}
}

Nginx 错误日志

2021/07/14 12:09:46 [emerg] 2597#2597: BIO_new_file("/etc/ssl/certs/ssl-cert-snakeoil.pem") Failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/ssl/certs/ssl-cert-snakeoil.pem','r') error:2006D080:BIO routInes:BIO_new_file:no such filE)
2021/07/14 12:39:37 [error] 882#882: *1 directory index of "/var/www/" is forbIDden,clIEnt: 165.225.xxx.xxx,server: nextcloud.mydomain.vip,request: "GET / http/1.1",host: "nextcloud.mydomain.vip"
2021/07/14 12:39:40 [error] 882#882: *2 open() "/var/www/favicon.ico" Failed (2: No such file or directory),server: nextcloud: No such file or directory),server: nextcloud.mydomain.vip",referrer: "https://nextcloud.mydomain.vip/"

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的NGINX - 重定向过多,然后 403 禁止全部内容,希望文章能够帮你解决NGINX - 重定向过多,然后 403 禁止所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。