快速背景:我有Nginx配置的代码。 目标是实现完整站点CDN缓存,因此需要对HTTP请求处理进行一些更改,因此需要更改代码。
问题:我不知道如何将代码“翻译”成Apache语言。
如果您可以帮助我翻译该代码,将不胜感激!
这是nginx代码:
server {
server_name origin.example.com;
listen 80;
root /var/www/example;
index index.php index.html index.htm;
set $cache_path $request_uri;
# bypass cache for POST requests
if ( $request_method = POST ) {
set $cache_path 'nocache';
}
# don't cache login/admin URLs
if ($request_uri ~* "/(wp-login.php|wp-admin|login.php|backend|admin)"){
set $cache_path 'nocache';
}
# don't cache if there is a cookie called PHPSESSID
if ($http_cookie ~* "PHPSESSID"){
set $cache_path 'nocache';
}
# bypass cache for logged in users
if ( $http_cookie ~ (wp-postpass|wordpress_|comment_author)_ ) {
set $cache_path 'nocache';
}
# bypass cache if query string not empty
if ( $query_string ) {
set $cache_path 'nocache';
}
location / {
# this line is specific to Cache Enabler
try_files /wp-content/cache/cache-enabler/${http_host}${cache_path}index.html $uri $uri/ /index.php?$args;
if ($cache_path = 'nocache') {
expires -1;
add_header Cache-Control no-cache;
}
}
# php7 fastcgi
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
...
fastcgi_intercept_errors on;
if ($cache_path = 'nocache') {
expires -1;
add_header Cache-Control no-cache;
}
if ($cache_path != 'nocache') {
expires +1h;
}
}
# static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
log_not_found off;
add_header Cache-Control "max-age=604800, stale-while-revalidate=86400, stale-if-error=604800";
}
}
这是.htaccess的当前内容:
# BEGIN rlrssslReallySimpleSSL rsssl_version[3.0.5]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
1)我可以仅将新代码复制并粘贴到底部,还是需要以某种方式“嵌入”它?
2)我如何准确翻译“ root / var / www / example;”的nginx行?这应该指向.htaccess文件所在的路径吗?
非常感谢您的帮助!