source

Nginx에서 Larabel과 함께 WordPress를 설치하는 방법(SEO 친화적인 URL)

factcode 2023. 4. 4. 22:30
반응형

Nginx에서 Larabel과 함께 WordPress를 설치하는 방법(SEO 친화적인 URL)

Nginx에 라라벨 사이트가 있는데 괜찮아요

다음과 같은 일반 폴더 구조를 가지고 있습니다.

/app
/public
/vendor
...

/public폴더는 Laravel index.php가 있는 곳입니다.

WordPress를 설치했습니다./public/blog왜냐하면 나는 내 블로그를 볼 수 있게 하고 싶기 때문이다.mywebsite.org/blog.

현재 블로그는 에서 정의된 Permalink 설정을 그대로 두면 정상적으로 동작합니다./blog/wp-admin/options-permalink.php"기본값"으로 설정(즉, 게시물의 URL은 다음과 같습니다)/blog/?p=123Permalink Settings를 변경하면 투고를 표시할 없습니다(Larabel 404 페이지가 표시됩니다).

제 블로그 투고는 반드시 SEO 친화적인 URL(예쁜 퍼머링크)을 가지고 싶습니다.

현재 Nginx 설정은 다음과 같습니다.

server {
    #This config is based on https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf and seemed to be necessary to get Laravel working.
    server_name mysite.local;

     # The location of our project's public directory.
    root F:/code/mysite/public/;

     # Point index to the Laravel front controller.
    index           index.php;

    location / {
        # URLs to attempt, including pretty ones.
        try_files   $uri $uri/ /index.php?$query_string;
    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
            rewrite     ^/(.+)/$ /$1 permanent;
    }

    # Yoast WordPress SEO plugin says to add these 2 rewrites:
    rewrite ^/blog/sitemap_index\.xml$ /blog/index.php?sitemap=1 last;
    rewrite ^/blog/([^/]+?)-sitemap([0-9]+)?\.xml$ /blog/index.php?sitemap=$1&sitemap_n=$2 last;

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9123
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9123;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~* \.(css|js|gif|jpe?g|png)$ {
        #images, CSS, and JS have 1 week expiration: http://aspyct.org/blog/2012/08/20/setting-up-http-cache-and-gzip-with-nginx/ See also: http://serverfault.com/questions/339240/chromium-audit-says-its-not-caching-static-content-yet-headers-are-set-who-i
        expires 168h;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

}

아래 나열된 다른 답변들을 검토하는 데 몇 시간이 걸렸지만 이 작업을 수행하는 방법을 찾지 못했습니다.

제안사항?

P.S. WordPress 파일 설치 장소(예:/public/blog한 단계 더 올라가거나/blog또는/wordpress).

모든 걸 라라벨로 연결해서/위치, 단, 모든 것을 기입해야 합니다./blog/인덱스로 이동합니다./blog/index.php:

location /blog/ {
    try_files $uri $uri/ @wordpress;
}

location @wordpress {
    rewrite /blog/ /blog/index.php;
}

php 핸들러는 패스 정보 지원이 필요합니다.

location ^/blog/index.php(/.*)?$ {
    fastcgi_split_path_info ^(/blog/index.php)(/.*)$;
    fastcgi_pass   127.0.0.1:9123;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO $fastcgi_path_info;
    include fastcgi_param;
}

에러 로그의 디버깅 상세 설정을 유효하게 하고, 로그 정보를 투고합니다.

업데이트: 최초 질문자의 메모:

다음은 새로운 Nginx 설정의 일부입니다.이 설정은 /, /blog, /course, /blog/innitially-happy 및 /blog/sitemap_index.xml의 URL에 적합한 것 같습니다.

...
error_log /Users/myuser/code/myproject/storage/logs/nginx_error.log debug;

 # Point index to the Laravel front controller.
index           index.php;

location /blog/ {
    try_files $uri $uri/ @wordpress;
}

location @wordpress {
    rewrite /blog/ /blog/index.php;
}

location ^/blog/index.php(/.*)?$ {
    fastcgi_split_path_info ^(/blog/index.php)(/.*)$;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}
...

언급URL : https://stackoverflow.com/questions/23645386/how-to-install-wordpress-alongside-laravel-on-nginx-with-pretty-permalinks-seo

반응형