從 Mautic 網址中刪除 index.php 的配置規則和方法,簡短鏈接更方便。

正在查看 2 個帖子:1-2 (共 2 個帖子)
  • 作者
    帖子
  • 詩語
    管理員
    • 文章數量: 5,925
    @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,925
    @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 個帖子)
  • 哎呀,回覆話題必需登錄。

話題信息

  • 當前位於:Mautic
  • 1 條回覆
  • 1 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/feibisi/" title=" 查看詩語的個人資料" class="bbp-author-link"><span class="bbp-author-name"> 詩語</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/32066/#post-32067" title=" 回覆至:從 Mautic 網址中刪除 index.php 的配置規則和方法,簡短鏈接更方便。">5 年、 10 月前</a>