我已将Mautic安装在子文件夹中,例如:example.com/m
大多数 Mautic 在我的配置(管理面板,使用 Mautic 等)中运行良好,但对于我的子文件夹中的一些重定向,我得到404
:
example.com/m 200
example.com/m/form/9 200
example.com/m/form/generate.js?id=9 404
(/form 不存在 - 它应该由 Mautic 动态重定向/生成)
文件系统上的所有文件都属于 www-data。
我的主机 nginx conf:
server {
server_name www.example.com;
rewrite_log on;
root /var/www/example.com/www.example.com;
index index.php index.html index.htm;
access_log /var/log/nginx/example.com_access.log;
error_log /var/log/nginx/example.com_error.log notice;
#######################################
## Start Mautic Specific config #####
#######################################
location /m {
# Working despite forms:
try_files $uri $uri/ /m/?q=$uri&$args;
}
#######################################
## End Mautic Specific config #####
#######################################
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
# disable access to hidden files
location ~ /\.ht {
access_log off;
log_not_found off;
deny all;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/stats.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/stats.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 443 ssl;
server_name example.com;
listen [::]:443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/stats.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/stats.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
return 301 https://www.example.com$request_uri;
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name example.com www.example.com;
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
#return 404; # managed by Certbot
}
我究竟做错了什么?
您希望以 开头的 URI
/m
由location /m
块处理。但是,正则表达式位置优先,因此 URI
/m/form/generate.js
实际上由另一个位置处理,该位置与所有以 . 结尾的 URI 匹配.js
。请参阅此文档。有一个
^~
运算符强制前缀位置优先,但这在您的情况下不起作用,因为应用程序是 PHP,并且您需要.php
以块处理的URIlocation ~ \.php$
。因此,我建议您将
location
导致问题的原因嵌套在location /
块中。例如: