从 Mautic 网址中删除 index.php 的配置规则和方法,简短链接更方便。

从 Mautic 网址中删除 index.php 的配置规则和方法,简短链接更方便。


正在查看 2 个帖子:1-2 (共 2 个帖子)
  • 作者
    帖子
  • 诗语
    管理员
    • 文章数量: 5,866
    @feibisi
    楼主

    其实这个并不是必要的,只是刚直接输入我们的 Mautic 安装域名访问的时候发现居然是 404 ,弄得我还以为是莫名其妙的又坏了。

    由于我们是用的 Nginx 环境,所以需要编辑 Nginx 的网站配置文件,加入下面这一段就可以直接去掉 index.php,短点儿也好,方便。

    
        # redirect index.php to root
        rewrite ^/index.php/(.*) /$1  permanent;
    
        #######################################
        ##  Start Mautic Specific config #####
        #######################################
    
        # redirect some entire folders
        rewrite ^/(vendor|translations|build)/.* /index.php break;
    
        location / {
    		# First attempt to serve request as file, then
    		# as directory, then fall back to index.html
            # one option: try_files $uri $uri/ /index.php$is_args$args;
            try_files $uri /index.php$is_args$args;
     		# Uncomment to enable naxsi on this location
    		# include /etc/nginx/naxsi.rules
    	}
    
    诗语
    管理员
    • 文章数量: 5,866
    @feibisi
    楼主

    完整的 Mautic 的 Nginx 配置参考规则如下:

    server {
        # see: https://wiki.nginx.org/Pitfalls
        # see: https://wiki.nginx.org/IfIsEvil
        listen 80;
    
        root /app;
        index index.html index.htm index.php;
        error_page 404 /index.php;
    
        # Make site accessible from https://set-ip-address.xip.io
        server_name localhost;
    
        access_log /var/log/nginx/access.log;
        error_log  /var/log/nginx/error.log error;
    
        charset utf-8;
    
        # redirect index.php to root
        rewrite ^/index.php/(.*) /$1  permanent;
    
        #######################################
        ##  Start Mautic Specific config #####
        #######################################
    
        # redirect some entire folders
        rewrite ^/(vendor|translations|build)/.* /index.php break;
    
        location / {
    		# First attempt to serve request as file, then
    		# as directory, then fall back to index.html
            # one option: try_files $uri $uri/ /index.php$is_args$args;
            try_files $uri /index.php$is_args$args;
     		# Uncomment to enable naxsi on this location
    		# include /etc/nginx/naxsi.rules
    	}
    
        # 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
        location = /favicon.ico {
        	log_not_found off;
        	access_log off;
        }
    
        # Don't log robots
        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;
        }
    
        #######################################
        ##  End Mautic Specific config #####
        #######################################
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    	#
        location ~ \.php$ {
            # try_files $uri =403;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }
    }

    按需选用吧,修改文件的细节就不讲了,有问题跟帖留言,但基本上会折腾这个的也都应该是有一定技术能力的。

正在查看 2 个帖子:1-2 (共 2 个帖子)
  • 哎呀,回复话题必需登录。

未找到对应子版块?请直接在 [疑难杂症] 版块中发帖提问。

收藏纪念品


有奖活动

参与论坛社区问答,有机会获赠文派瓦普(Wapuu.com)手办模型。

话题信息

商业系统