fususu
September 15, 2017, 6:15am
1
I’m trying to add a mautic form to my site via javascript. But the form won’t show.
When I click to the link https://mt.fususu.com/form/generate.js?id=5 it just show a 404 file not found.
It also happen to mt.fususu.com/mtc.js and the tracking code won't work as well.
I've search around and tried these fixes below, but not work.
1.
Checking install base url
2.
Add some code in the nginx config.
I installed Mautic on a VPS, nginx 1.12/ php 7.1. Below is my current virtualhost
Code:
server {
listen 80;
server_name mt.fususu.com;
rewrite ^(.*) https://mt.fususu.com$1 permanent;
}
server {
listen 443 ssl http2;
# access_log off;
access_log /home/mt.fususu.com/logs/access.log;
# error_log off;
error_log /home/mt.fususu.com/logs/error.log;
# some ssl certificate code here
root /home/mt.fususu.com/public_html;
index index.php index.html index.htm;
server_name mt.fususu.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Custom configuration
include /home/mt.fususu.com/public_html/*.conf;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_connect_timeout 1000;
fastcgi_send_timeout 1000;
fastcgi_read_timeout 1000;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME /home/mt.fususu.com/public_html$fastcgi_script_name;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location /php_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/mt.fususu.com/public_html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
allow 127.0.0.1;
deny all;
}
location ~ /. {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* .(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|woff2|ttf|woff)$ {
gzip_static off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
location ~* .(txt|js|css)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
location ~ mtc.js{
try_files $uri @phpstream;
}
location ~ generate.js{
try_files $uri @phpstream;
}
location @phpstream {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
fususu
September 15, 2017, 6:15am
2
I’m trying to add a mautic form to my site via javascript. But the form won’t show.
<script type="text/javascript" src="//mt.fususu.com/form/generate.js?id=5"></script>
When I click to the link https://mt.fususu.com/form/generate.js?id=5 it just show a 404 file not found.
It also happen to mt.fususu.com/mtc.js and the tracking code won’t work as well.
I’ve search around and tried these fixes below, but not work.
Checking install base url
Add some code in the nginx config.
I installed Mautic on a VPS, nginx 1.12/ php 7.1. Below is my current virtualhost
server {
listen 80;
server_name mt.fususu.com;
rewrite ^(.*) https://mt.fususu.com$1 permanent;
}
server {
listen 443 ssl http2;
# access_log off;
access_log /home/mt.fususu.com/logs/access.log;
# error_log off;
error_log /home/mt.fususu.com/logs/error.log;
# some ssl certificate code here
root /home/mt.fususu.com/public_html;
index index.php index.html index.htm;
server_name mt.fususu.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Custom configuration
include /home/mt.fususu.com/public_html/*.conf;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_connect_timeout 1000;
fastcgi_send_timeout 1000;
fastcgi_read_timeout 1000;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME /home/mt.fususu.com/public_html$fastcgi_script_name;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location /php_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/mt.fususu.com/public_html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
allow 127.0.0.1;
deny all;
}
location ~ /. {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* .(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|woff2|ttf|woff)$ {
gzip_static off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
location ~* .(txt|js|css)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
location ~ mtc.js{
try_files $uri @phpstream;
}
location ~ generate.js{
try_files $uri @phpstream;
}
location @phpstream {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
fususu
September 15, 2017, 3:41pm
3
Up, anyone can fix this before?
Alcides
September 26, 2017, 7:26pm
5
hi! @fususu
I am facing the same issue.
I am using the following extra setup for Mautic.
My issue is that CSS and JS files are not beeing load.
I am new with NGINX, I have no idea in which direction should I go.
Did you solve it?
Thanks.
START - Mautic Configuration
# redirect index.php to root
rewrite ^/index.php/(.*) /$1 permanent;
# redirect some entire folders
rewrite ^/(vendor|translations|build)/.* /index.php break;
# ---- START - Mautic Protections ---- #
#Deny everything else in /app folder except Assets folder in bundles
location ~ /app/bundles/.*/Assets/ {
allow all;
access_log off;
}
location ~ /app/ {
deny all;
}
#Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /(addons|plugins)/.*/Assets/ {
allow all;
access_log off;
}
location ~ /(addons|plugins)/ {
deny all;
}
#Deny all php files in themes folder
location ~* ^/themes/(.*).php {
deny all;
}
#Don't log favicon
# It is not necessary because it is already in /usr/local/nginx/conf/drop.conf
# I am using centminmod.com
#location = /favicon.ico {
# log_not_found off;
# access_log off;
#}
#Don't log robots
# It is not necessary because it is already in /usr/local/nginx/conf/drop.conf
# I am using centminmod.com
#location = /robots.txt {
# access_log off;
# log_not_found off;
#}
#Deny yml, twig, markdown, init file access
location ~* /(.*).(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
deny all;
access_log off;
log_not_found off;
}
#Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /. {
deny all;
access_log off;
log_not_found off;
}
#Deny all grunt, composer files
location ~* (Gruntfile|package|composer).(js|json)$ {
deny all;
access_log off;
log_not_found off;
}
#Allowing the file manager to execute
location ~ /app/bundles/CoreBundle/Assets/js/libraries/ckeditor/filemanager/connectors/php/filemanager.php {
allow all;
}
# ---- END - Mautic Protections ---- #
location / {
# First attempt to serve request as file, then as directory, then fall back to index
try_files $uri $uri/ /index.php$is_args$args;
}
END - Mautic Configuration
fususu
September 27, 2017, 1:22am
6
Hi @Alcides
Unfortunately I haven’t solved it yet. And this caused the email tracking function not working, too.
But I know for sure it’s the config nginx problem. Due to some restrict config, that nginx looking for the particular file mtc.js, and if not found it give the 404 error, while Mautic using the dynamic content, it will call that file via PHP script.
So I tried to pass the mtc.js file to the php via 127.0.0.1:9000 by these code, but no luck
location ~ mtc.js{
try_files $uri @phpstream;
}
location @phpstream {
fastcgi_pass fastcgi_pass 127.0.0.1:9000;
}
It may work if we pass the php to listen to sock, instead of the ip like this https://stackoverflow.com/questions/44757189/where-is-php7-0-fpm-sock-located but I’m not trying yet.
Alcides
September 27, 2017, 7:33pm
7
@fususu
I got what you have said.
Today I rebuild my server completelly to exclude any past mistake but the issue is still there.
I tryied HTTP and HTTPS and the results are the same.
I have no idea for while how to solve it. If you have, please, let me know.
Thanks a lot.
fususu
September 28, 2017, 4:43am
8
@alcides Not any luck. I’m hiring some guys here to help https://www.freelancer.com/projects/linux/fix-issue-when-using-mautic/#/proposals , minimum is 21$ :)) can we share? maybe he will fix for both of us.
Alcides
September 28, 2017, 2:53pm
9
hi! @fususu
Sure If the person really find the reason knowing what they are doing I can share it.
Please tell me about your server environment setup.
Mine is very simple:
1 - CentOS 7
2 -LEMP install script (https://centminmod.com ) version 123.09beta01
OBS: I decided to use this version instead of the 123.08stable just because the new one has the hability to auto add a Let’s Encrypt SSL to a virtualhost setup.
Have you tested it?
Thanks,
Alcides
September 28, 2017, 3:11pm
10
Hi! @fususu
Based on this post: https://www.mautic.org/community/index.php/5944-e-mail-open-tracking-404/0#p16733
I believe I could solve it my adding the lines bellow:
The 404 Error is not anymore but I sill have some CSS load errors.
Solve e-Mail Open Tracking 404 Error
location ~ email/(.*).gif {
try_files $uri /index.php?$args;
}
Solve JS Loading 404 Error
location ~ (.*).js {
try_files $uri /index.php?$args;
}
Please, have a look if it can solve also your issue.
Best regards!
Alcides
fususu
September 29, 2017, 7:42am
11
[quote=26216:@Alcides ]Hi! @fususu
Solve e-Mail Open Tracking 404 Error
location ~ email/(.*).gif {
try_files $uri /index.php?$args;
}
Solve JS Loading 404 Error
location ~ (.*).js {
try_files $uri /index.php?$args;
}
[/quote]
I tried this before but not work. I’m using Centos 7 and LEMP just like you.
Still waiting for the miracle happens…
fususu
September 29, 2017, 9:04am
12
Hey, after one hour messing around with the nginx config I found the root cause of my problem and solved it!
Here is what I did:
I notice that when visit mydomain.com/whatever --> it show a mautic 404 page. but when visit mydomain.com/mtc.js it show just a 404 of Nginx ==> it must be some pre-configs related to that the file js causes this.
Then I search in my nginx config and see that there is another block that config the css & js file:
location ~* .(txt|js|css)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
I just comment all the code. Then the miracle appeared! 404 not found of mydomain/mtc.js gone!
P.s. I also add these code below to config the js & gif file
# Solve email tracking pixel not found
location ~ email/(.*).gif {
try_files $uri /index.php?$args;
}
# Solve JS Loading 404 Error
location ~ (.*).js {
try_files $uri /index.php?$args;
}
P.p.s. this solution also help me solve open mail tracking issues. I just delete |gif from the code in my pre-config
location ~* .(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|woff2|ttf|woff)$ {
gzip_static off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
arjon
October 26, 2017, 4:38pm
13
@fususu Can you please publish the full mautic config for nginx?
fususu
October 27, 2017, 7:45am
14
Here is my full nginx that works well with mautic now, also using SSL.
server {
listen 80;
server_name subdomain.mydomain.com;
rewrite ^(.*) https://subdomain.mydomain.com$1 permanent;
}
server {
listen 443 ssl http2;
# access_log off;
access_log /home/subdomain.mydomain.com/logs/access.log;
# error_log off;
error_log /home/subdomain.mydomain.com/logs/error.log;
root /home/subdomain.mydomain.com/public_html;
index index.php index.html index.htm;
server_name subdomain.mydomain.com;
#( some SSL related was removed )
location / {
try_files $uri $uri/ /index.php?$args;
}
# Custom configuration
include /home/subdomain.mydomain.com/public_html/*.conf;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_connect_timeout 1000;
fastcgi_send_timeout 1000;
fastcgi_read_timeout 1000;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME /home/subdomain.mydomain.com/public_html$fastcgi_script_name;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location /php_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/subdomain.mydomain.com/public_html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
allow 127.0.0.1;
deny all;
}
location ~ /. {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* .(3gp|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|woff2|ttf|woff)$ {
gzip_static off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
#location ~* .(txt|js|css)$ {
#add_header Pragma public;
#add_header Cache-Control "public, must-revalidate, proxy-revalidate";
#access_log off;
#expires 30d;
#break;
#}
location ~* .(eot|otf|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}
# Solve email tracking mautic
location ~ email/(.*).gif {
try_files $uri /index.php?$args;
}
# Solve JS Loading 404 Error
location ~ (.*).js {
try_files $uri /index.php?$args;
add_header Access-Control-Allow-Origin *;
}
}
arjon
October 27, 2017, 10:01am
15
@fususu what does this line have include /home/subdomain.mydomain.com/public_html/*.conf;
arjon
October 27, 2017, 10:18am
16
I get error 405 for /mtc/event and 404 for mtracking.gif
arjon
October 27, 2017, 10:21am
17
Fixed error 404 for mtracking.gif. Edited
location ~ email/(.*).gif {
try_files $uri /index.php?$args;
}
to
location ~ (.*).gif {
try_files $uri /index.php?$args;
}
fususu
October 28, 2017, 8:40am
18
Some wordpress plugins may create custom nginx file in the public_html folder, this line will include that custom conf file. Anyway, it’s not related to Mautic ^^!
–
Nice to be here with you guys, let’s make a great community.
My blog: https://fususu.com/en/ My fb: Facebook
arjon
October 28, 2017, 2:02pm
19
[quote=26769:@fususu ]Some wordpress plugins may create custom nginx file in the public_html folder, this line will include that custom conf file. Anyway, it’s not related to Mautic ^^!
–
Nice to be here with you guys, let’s make a great community.
My blog: https://fususu.com/en/ My fb: https://fb.com/fususuvn[/quote]
Why did you put “/home/subdomain.mydomain.com/public_html” at PHP location?
fususu
October 30, 2017, 6:01am
20
It’s related to some optimized configs for the VPS that was pre-installed before. I used the script here to setup VPS in 15 minutes with all things I need Cài đặt và Quản lý server dễ dàng với HocVPS Script - Học VPS