我的问题是我有一个CentOS网络面板:
其中,在端口80/443上运行Nginx反向代理,它将请求转发到端口8181上的Apache 2.4.52。Apache使用的模块是:
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
deflate_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
expires_module (shared)
headers_module (shared)
unique_id_module (shared)
setenvif_module (shared)
version_module (shared)
proxy_module (shared)
proxy_connect_module (shared)
proxy_http_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
userdir_module (shared)
alias_module (shared)
rewrite_module (shared)
ssl_module (shared)
security2_module (shared)
proxy_fcgi_module (shared)
rpaf_module (shared)
suphp_module (shared)
Apache使用PHP-FPM8.0.20当前这个PHP服务器上的,我有一个Wordpress安装,带有WebP Express。我在其他主机和页面上使用了它,但它说,目前它无法工作,因为我没有安装mod_headers。我尝试了它和mod_headers工作,我能够改变缓存和其他头部,但不知怎的,它并没有重定向到.webp图像。
目前,在其他主机上的示例中,如果我请求服务器提供一个映像,我得到了以下标题: URL:https://www.workingexampleurl.com/wp-content/uploads/2022/05/test.png
date: Tue, 26 Jul 2022 09:56:25 GMT
server: Apache
last-modified: Thu, 19 May 2022 16:26:32 GMT
etag: "dcf6-5df5fd632cd92"
accept-ranges: bytes
content-length: 56566
vary: Accept
x-webp-express: Redirected directly to existing webp
cache-control: private, max-age=2592000
content-type: image/webp
在这个主机安装程序中,我得到了以下内容: URL:https://notworkingexampleurl.com/wp-content/uploads/2022/07/test.png
server: nginx/1.22.0
date: Tue, 26 Jul 2022 09:59:37 GMT
content-type: image/png
content-length: 46758
last-modified: Thu, 21 Jul 2022 15:12:12 GMT
connection: keep-alive
keep-alive:timeout=60
vary: Accept-Encoding
etag: "62d96ccc-b6a6"
expires: Thu, 31 Dec 2037 23:55:55 GMT
cache-control: max-age=315360000
x-cache: HIT from Backend
strict-transport-security: max-age=31536000
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
accept-ranges: bytes
当我使用apache 8181端口尝试使用相同的域时,我从服务器获得了以下标题:
Date: Tue, 26 Jul 2022 10:27:09 GMT
Server: Apache/2.4.52 (Unix) OpenSSL/1.0.2k-fips
Vary: Accept,User-Agent
Last-Modified: Tue, 26 Jul 2022 08:22:25 GMT
ETag: "7fc6-5e4b1001bf660"
Accept-Ranges: bytes
Content-Length: 32710
X-WebP-Express: Redirected directly to existing webp
Content-Type: image/webp
在/etc/nginx/proxy.inc文件中有以下内容:
#More info here: http://wiki.nginx.org/HttpProxyModule
proxy_buffering off;
proxy_connect_timeout 59s;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_pass_header Set-Cookie;
proxy_redirect off;
#proxy_hide_header Vary;
proxy_hide_header X-Powered-By;
proxy_set_header Accept-Encoding '';
#If you want to get the cache-control and expire headers from apache, comment out 'proxy_ignore_headers' and uncomment 'proxy_pass_header Expires;' and 'proxy_pass_header Cache-Control
proxy_pass_header Expires;
proxy_pass_header Cache-Control;
proxy_pass_header Vary;
#proxy_pass_request_headers on;
#proxy_ignore_headers Cache-Control Expires;
proxy_set_header Referer $http_referer;
proxy_set_header Host $host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
这是nginx代理上vhost的配置:/etc/nginx/conf.d/vhosts/notworkingexample.hu.ssl.conf
server {
listen 192.168.1.15:443 ssl ;
server_name notworkingexample.hu www.notworkingexample.hu;
access_log /usr/local/apache/domlogs/notworkingexample.hu.bytes bytes;
access_log /usr/local/apache/domlogs/notworkingexample.hu.log combined;
error_log /usr/local/apache/domlogs/notworkingexample.hu.error.log error;
ssl_certificate /etc/pki/tls/certs/notworkingexample.hu.bundle;
ssl_certificate_key /etc/pki/tls/private/notworkingexample.hu.key;
ssl_protocols TLSv1.2;
ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA!RC4:EECDH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 60m;
location / {
location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh|webp)$ {
root /home/superuser/public_html/notworkingexample.hu;
expires max;
try_files $uri $uri/ @backend;
}
error_page 405 = @backend;
error_page 500 = @custom;
add_header X-Cache "HIT from Backend";
add_header Strict-Transport-Security "max-age=31536000";
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
proxy_pass http://192.168.1.15:8181;
include proxy.inc;
}
location @backend {
internal;
proxy_pass http://192.168.1.15:8181;
include proxy.inc;
}
location @custom {
internal;
proxy_pass http://192.168.1.15:8181;
include proxy.inc;
}
location ~ .*\.(php|jsp|cgi|pl|py)?$ {
proxy_pass http://192.168.1.15:8181;
include proxy.inc;
}
location ~ /\.ht {deny all;}
location ~ /\.svn/ {deny all;}
location ~ /\.git/ {deny all;}
location ~ /\.hg/ {deny all;}
location ~ /\.bzr/ {deny all;}
disable_symlinks if_not_owner from=/home/superuser/public_html/notworkingexample.hu;
location /.well-known/acme-challenge {
default_type "text/plain";
alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
}
location /.well-known/pki-validation {
default_type "text/plain";
alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
}
}
最后,这是当前域的配置,不工作的/usr/local/apache/conf.d/vhosts/notworkingexample.hu.conf:
ServerName notworkingexample.hu
ServerAlias www.notworkingexample.hu
ServerAdmin webmaster@notworkingexample.hu
DocumentRoot /home/superuser/public_html/notworkingexample.hu
UseCanonicalName Off
ScriptAlias /cgi-bin/ /home/superuser/public_html/notworkingexample.hu/cgi-bin/
#CustomLog /usr/local/apache/domlogs/notworkingexample.hu.bytes bytes
#CustomLog /usr/local/apache/domlogs/notworkingexample.hu.log combined
ErrorLog /usr/local/apache/domlogs/notworkingexample.hu.error.log
# Custom settings are loaded below this line (if any exist)
IncludeOptional "/usr/local/apache/conf/userdata/superuser/notworkingexample.hu/*.conf"
SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on
UserDir disabled
UserDir enabled superuser
SuexecUserGroup superuser superuser
suPHP_UserGroup superuser superuser
suPHP_ConfigPath /home/superuser
RMode config
RUidGid superuser superuser
AssignUserID superuser superuser
AllowOverride All
Require all granted
SetHandler "proxy:unix:/opt/alt/php-fpm80/usr/var/sockets/superuser.sock|fcgi://localhost"
任何建议都会很好!
发布于 2022-07-26 13:18:42
经过越来越多的试验,我发现了这个问题。我尝试了另一个Nginx代理服务器,它成功了,所以我搜索并测试了配置。问题在于vhost nginx配置中的这个部分,我删除了jpg、jpeg、png和webp扩展,而不是它应该工作的部分:
(3gp|gif|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh)$ {
root %docroot%;
expires max;
try_files $uri $uri/ @backend;
}
https://serverfault.com/questions/1106627
复制相似问题