【问题标题】:Wordpress inside Laravel Public folderLaravel 公共文件夹中的 Wordpress
【发布时间】:2018-04-14 02:43:35
【问题描述】:

我想为我的 laravel 应用展示一些来自 Wordpress 的不那么重要的内容页面。

我已经在我的 laravel 应用程序的public/pages 文件夹中安装了 Wordpress。

然而,我面临的问题是漂亮的链接(laravel.app/pages/sample-page)抛出 404,因为它们是由 laravel 处理的。

我该如何解决这个问题?我假设它必须在 nginx 配置文件上处理。

该站点托管在 Laravel Forge 上,这里是 nginx 配置文件:

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/laravel.app/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name .laravel.app;
    root /home/forge/laravel.app/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/laravel.app/264952/server.crt;
    ssl_certificate_key /etc/nginx/ssl/laravel.app/264952/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'xxx';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/laravel.app/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/laravel.app-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/laravel.app/after/*;

提前致谢。

【问题讨论】:

    标签: php wordpress laravel


    【解决方案1】:

    我会将 wordpress 安装到 Laravel 项目之外的它自己的文件夹中,并使用 nginx 配置页面的位置 像

    location ^/pages/index.php(/.*)?$ {
        fastcgi_split_path_info ^(/pages/index.php)(/.+)$;
        OTHER CONFIG
    }
    
    location /pages/ {
        if (!-e $request_filename) {
                rewrite ^.*$ /pages/index.php last;
            }
         OTHER CONFIG
    }
    

    【讨论】:

      【解决方案2】:

      环顾四周,并尝试了一些可用的变体 - 这是一个有效的 nginx 配置:

      # FORGE CONFIG (DOT NOT REMOVE!)
      include forge-conf/laravel.app/before/*;
      
      server {
          listen 443 ssl http2;
          listen [::]:443 ssl http2;
          server_name .laravel.app;
          root /home/forge/laravel.app/public;
      
          # FORGE SSL (DO NOT REMOVE!)
          ssl_certificate /etc/nginx/ssl/laravel.app/264952/server.crt;
          ssl_certificate_key /etc/nginx/ssl/laravel.app/264952/server.key;
      
          ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
          ssl_ciphers 'XXX';
          ssl_prefer_server_ciphers on;
          ssl_dhparam /etc/nginx/dhparams.pem;
      
          add_header X-Frame-Options "SAMEORIGIN";
          add_header X-XSS-Protection "1; mode=block";
          add_header X-Content-Type-Options "nosniff";
      
          index index.html index.htm index.php;
      
          charset utf-8;
      
          # FORGE CONFIG (DOT NOT REMOVE!)
          include forge-conf/laravel.app/server/*;
      
          location /blog/index.php(/.*)?$ {        
              fastcgi_split_path_info ^(/blog/index.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              fastcgi_read_timeout 1000;
              fastcgi_param PATH_INFO $fastcgi_path_info;
              include fastcgi_params;
          }
          location /blog/ { 
              if (!-e $request_filename) {
                      rewrite ^.*$ /blog/index.php last;    
                  }
              try_files $uri $uri/ blog/index.php?args; 
          }
      
          location / {
              try_files $uri $uri/ /index.php?$query_string;
          }
      
          location = /favicon.ico { access_log off; log_not_found off; }
          location = /robots.txt  { access_log off; log_not_found off; }
      
          access_log off;
          error_log  /var/log/nginx/laravel.app-error.log error;
      
          error_page 404 /index.php;
      
          location ~ \.php$ {
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
              fastcgi_index index.php;
              include fastcgi_params;
          }
      
          location ~ /\.(?!well-known).* {
              deny all;
          }
      }
      
      # FORGE CONFIG (DOT NOT REMOVE!)
      include forge-conf/laravel.app/after/*;
      

      【讨论】:

        猜你喜欢
        • 2020-12-04
        • 2020-05-09
        • 2017-02-03
        • 1970-01-01
        • 2016-03-31
        • 2020-01-27
        • 2016-01-24
        • 2018-10-16
        • 1970-01-01
        相关资源
        最近更新 更多