如何解决Nginx 多站点 Wordpress 加载资源失败:服务器响应状态为 503
事实上,我对 nginx 和多站点非常陌生。我一直在阅读指南,但今天我遇到了这个错误,它破坏了多站点的子域。
老实说,我不知道错误在哪里以及我应该如何配置它。我觉得一切都已经一团糟。
我知道我可以添加白名单,但是当我尝试输入我的 IP 时它不起作用......
这是我的 nginx.conf:
## For a live site,handling more connections,uncomment,then start WinNMP.exe --phpCgiServers=25:
worker_processes auto;
worker_rlimit_nofile 100000;
events {
## For a live site,uncomment:
worker_connections 8096;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
ssi off;
server_names_hash_bucket_size 64;
limit_req_zone $binary_remote_addr zone=main:10m rate=60r/m;
limit_conn_zone $binary_remote_addr zone=one:10m;
## Timeouts ##
##############
client_body_timeout 5;
client_header_timeout 5;
keepalive_timeout 25 25;
send_timeout 15s;
resolver_timeout 3s;
# Timeout period for connection with FastCGI-server. It should be noted that this value can't exceed 75 seconds.
fastcgi_connect_timeout 5s;
# Amount of time for upstream to wait for a fastcgi process to send data.
# Change this directive if you have long running fastcgi processes that do not produce output until they have finished processing.
# If you are seeing an upstream timed out error in the error log,then increase this parameter to something more appropriate.
fastcgi_read_timeout 40s;
# Request timeout to the server. The timeout is calculated between two write operations,not for the whole request.
# If no data have been written during this period then serve closes the connection.
fastcgi_send_timeout 15s;
## Buffers ##
#############
fastcgi_buffers 8 32k;
fastcgi_buffer_size 32k;
#fastcgi_busy_buffers_size 256k;
#fastcgi_temp_file_write_size 256k;
open_file_cache off;
# php max upload limit cannot be larger than this
client_max_body_size 33m;
####client_body_buffer_size 1K;
client_header_buffer_size 8k;
large_client_header_buffers 8 16k;
types_hash_max_size 2048;
include nginx.mimetypes.conf;
default_type text/html;
## Logging ##
#############
access_log "c:/winnmp/log/nginx_access.log";
error_log "c:/winnmp/log/nginx_error.log" warn; #debug or warn
log_not_found on; #enables or disables messages in error_log about files not found on disk.
rewrite_log off;
fastcgi_intercept_errors off; # Do Not Change (off) !
gzip off;
index index.php index.htm index.html;
server {
# NEVER ALLOW PUBLIC ACCESS TO THIS SERVER !!!
# Instead,create projects using WinNMP Manager,and allow public access only to those projects!
# How to allow access from LAN and Internet to your local project:
# http://WinNMP.wtriple.com/howtos.php#How-to-allow-access-from-LAN-and-Internet-to-your-local-project
listen 127.0.0.1:80 default_server; # Do Not Change ! Security Risk !
#listen [::1]:80 ipv6only=on; # Do Not Change ! Security Risk !
server_name localhost; # Do Not Change ! Security Risk !
# This directive is modified automatically by WinNMP.exe for portability.
root "c:/winnmp/www";
autoindex on;
allow 127.0.0.1; # Do Not Change ! Security Risk !
allow ::1; # Do Not Change ! Security Risk !
deny all; # Do Not Change ! Security Risk !
## deny access to .htaccess files,if Apache's document root concurs with nginx's one
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
}
location = /robots.txt {
log_not_found off;
}
## Tools are now served from include/tools/
location ~ ^/tools/.*\.php$ {
root "c:/winnmp/include";
try_files $uri =404;
include nginx.fastcgi.conf;
fastcgi_pass php_farm;
allow 127.0.0.1; # Do Not Change ! Security Risk !
allow ::1; # Do Not Change ! Security Risk !
deny all; # Do Not Change ! Security Risk !
}
location ~ ^/tools/ {
root "c:/winnmp/include";
allow 127.0.0.1; # Do Not Change ! Security Risk !
allow ::1; # Do Not Change ! Security Risk !
deny all; # Do Not Change ! Security Risk !
}
## How to add phpMyAdmin
## Copy phpMyAdmin files to c:/winnmp/include/phpMyAdmin then uncomment:
#location ~ ^/phpMyAdmin/.*\.php$ {
# root "c:/winnmp/include";
# try_files $uri =404;
# include nginx.fastcgi.conf;
# fastcgi_pass php_farm;
# allow 127.0.0.1;
# allow ::1;
# deny all;
#}
#location ~ ^/phpMyAdmin/ {
# root "c:/winnmp/include";
#}
## Notice that the root directive lacks /phpMyAdmin because Nginx adds the URL path /phpMyAdmin to the root path,so the resulting directory is c:/winnmp/include/phpMyAdmin
## PHP for localhost ##
#######################
location ~ \.php$ {
try_files $uri =404;
include nginx.fastcgi.conf;
include nginx.redis.conf;
fastcgi_pass php_farm;
allow 127.0.0.1; # Do Not Change ! Security Risk !
allow ::1; # Do Not Change ! Security Risk !
deny all; # Do Not Change ! Security Risk !
}
# How to allow access from LAN and Internet to your local project:
# http://WinNMP.wtriple.com/howtos.php#How-to-allow-access-from-LAN-and-Internet-to-your-local-project
}
include domains.d/*.conf;
include nginx.phpfarm.conf;
}
我知道错误应该在这个:
limit_req_zone $binary_remote_addr zone=main:10m rate=30r/m;
limit_conn_zone $binary_remote_addr zone=one:10m;
但无论值发生多少变化,它都会继续发生。
这是我现在使用的唯一子域的 * .conf:
server {
listen 80 deferred;
listen [::]:80 deferred;
server_name mainsite.net www.mainsite.net;
return 302 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate "c:/winnmp/conf/.acmephp/master/certs/mainsite.net/public/fullchain.pem";
ssl_certificate_key "c:/winnmp/conf/.acmephp/master/certs/mainsite.net/private/key.private.pem";
root "c:/winnmp/www/mainsite";
server_name mainsite.net;
server_name www.mainsite.net;
allow all;
autoindex on;
location ~ \.php$ {
try_files $uri =404;
include nginx.fastcgi.conf;
include nginx.redis.conf;
fastcgi_pass php_farm;
fastcgi_hide_header X-Powered-By;
}
location ~ ^/wordpress/\.user\.ini {
deny all;
}
## avoid processing of calls to non-existing static files
location ~* \.(js|css|png|jpg|jpeg|gif|swf|ico|pdf|mov|fla|zip|rar|7z|tar|tgz|gz|ttf|otf|eot|swg|woff|woff2)$ {
expires 1y;
try_files $uri =404;
}
location / {
limit_req zone=main burst=10 nodelay;
fastcgi_read_timeout 80s;
fastcgi_intercept_errors off;
try_files $uri $uri/ /index.php?$args;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location ~ \.(css|htc|less|js|js2|js3|js4)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header Referrer-Policy "no-referrer-when-downgrade";
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "max-age=3600,public";
add_header Referrer-Policy "no-referrer-when-downgrade";
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|avif|avifs|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header Referrer-Policy "no-referrer-when-downgrade";
try_files $uri $uri/ /index.php?$args;
}
add_header Referrer-Policy "no-referrer-when-downgrade";
# END W3TC Browser Cache
# BEGIN W3TC Minify core
rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last;
rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
# END W3TC Minify core
}
location /wp-login.php {
return 404;
}
location /wp-admin {
limit_conn one 10;
}
location /xmlrpc.php {
deny all;
}
}
server {
server_name subdomain.net;
location / {
return 302 https://$server_name$request_uri;
}
}
在这里我注意到我有两个配置:/wp-admin
我不用作 sub.mainsite.net 的子域,如果不是像 subdomain.net。我的意思是它有自己的网址。
错误是:状态为 503,适用于所有 .js 文件,并在 Chrome 中以隐身模式出现。而且该网站已完全损坏。
在没有隐身模式的 Chrome 中不会发生这种情况。同样使用 Edge,我在智能手机上的 Safari 中尝试过,结果发现它坏了。以前没有发生过。非常罕见。
这些是我在中断的子域中激活的插件:
Tawk.to 实时聊天 W3 总缓存 WP Cerber 安全、反垃圾邮件和恶意软件扫描 WP 邮件 SMTP 专业版 WP 重置 WPForms 精简版
我不知道是不是 Tawk.to Live Chat 是我激活的最后一个插件。
一切正常,我不知道还能做什么。
老实说,我不知道还有什么要改变,要留下什么或要删除什么,以便能够很好地构建网站。我害怕一切都会失去,我将不得不从零开始。
我希望你能帮助我,希望我能正确地整理我的 conf 文件。我觉得他们一团糟。
非常感谢。
编辑:我刚刚从两个文件的边界中删除了该行。它已经正常工作。该网站不是因为它是为一所学校而推出的,平均至少有 300 人会从一个拥有 2800 名用户的 Facebook 页面进入。该项目主要面向以前的学生,与学校无关。然后一切都靠我自己了。我担心的是服务器过载,或者有人试图攻击该站点。
所以如果出现错误,我应该放什么,放在哪里?在那里我完全迷失了自己。我很抱歉成为这样的新手,我提前道歉。谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。