code

Wordpress Rest API 역방향 프록시

starcafe 2023. 6. 27. 22:26
반응형

Wordpress Rest API 역방향 프록시

워드프레스로 역방향 프록시를 설정하고 몇 개의 경로를 제외하려고 합니다.내 제외 규칙은 관리자, ...를 포함하여 작동하지만 /wp-json/에는 작동하지 않습니다..ht 액세스 때문인 것 같습니다.저는 개츠비js에서 사용하기 때문에 나머지 api 데이터를 반환하기 위해 워드프레스가 필요합니다.

저는 이것을 알아내려고 하루 종일 노력했습니다.어떤 이유로 /wp-json/이 404를 반환하고 사이트의 프런트 엔드 부분이 있는 netlify 서버로 프록시됩니다.제가 프록시 규칙을 모두 제거하면 wp-json이 작동합니다.

.htaccess에는 기본 wordpress 항목이 포함되어 있습니다.

다음은 가상 호스트의 붙여넣기 상자입니다. https://pastebin.com/vFh6hCkN

<IfModule mod_ssl.c>
   <VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    Protocols h2 http/1.1
    ServerName  www.michaelharwinlaw.com
    ServerAlias michaelharwinlaw.com
    ServerAdmin webmaster@cyberserge.com
    DocumentRoot /var/www/html/

    <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    SSLProxyEngine on
    ProxyPass /wp-admin/ !
    ProxyPass /wp-login/ !
    ProxyPass /wp-json/ !
    ProxyPass /wp-content/plugins/ !
    ProxyPass /wp-includes/ !
    ProxyPassMatch .*\.xml !
    ProxyPass / https://stag.michaelharwinlaw.com/
    ProxyPassReverse / https://stag.michaelharwinlaw.com/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/mc-error.log
    CustomLog ${APACHE_LOG_DIR}/mc-access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Include /var/www/html/wp-content/uploads/wpseo-redirects/.redirects

    SSLCertificateFile /etc/letsencrypt/live/www.michaelharwinlaw.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.michaelharwinlaw.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

다음과 같은 이유로 작동하지 않습니다./wp-json실제 파일 또는 디렉토리가 아닙니다. 읽기 없이는.htaccess로컬 요청이 수신됩니다.404 not foundApache가 원격 서버로 계속 요청을 전달하도록 응답합니다.

이 URL 다시 쓰기를 수정하려면 요청을 로컬로 보내야 합니다.index.php.

교체하다ProxyPass /wp-json/ !와 함께

ProxyPass /index.php !
ProxyPass /wp-json !

/wp-json끝이 없는/둘 다에 대한 요청을 처리하는 데 필요합니다.domain/wp-json또는domain/wp-json/.

존재하지 않는 다른 URL은 원격 서버에서 처리됩니다.

설명서에서 페이지 탐색이 작동하지 않음 섹션을 참조하십시오.

"이는 워드프레스가 생성하는 .htaccess 파일의 결함 때문입니다.이 문제를 해결하려면 .htaccess 파일의 내용을 삭제하고 다시 만드십시오.

  1. 제어판에서 관리 > 파일로 이동합니다(파일 편집에 대한 자세한 내용);
  2. .htaccess 파일에 대한 링크를 클릭하여 내용을 편집합니다.
  3. 파일의 내용을 복사하여 텍스트 편집기의 텍스트 파일에 붙여넣습니다.이는 .htaccess 파일에 리디렉션, 거부 또는 기타 핸디 htaccess 트릭에 대한 수동 항목이 있는 경우의 예방 조치입니다.
  4. .htaccess 파일에서 모든 내용을 삭제하고 Update File 버튼을 클릭합니다.
  5. 제어판에서 옵션 > Permalinks;로 이동합니다.
  6. Permalink Structure 업데이트 버튼을 클릭하여 Permalink에 대한 새 다시 쓰기 규칙을 새로 생성합니다.
  7. 이전에 끊어진 링크를 사용하여 결과를 테스트합니다.
  8. 수동 htaccess 항목을 파일에 다시 추가합니다(# BEGIN WordPress 행 앞이나 # END WordPress 행 뒤에 수동 htaccess 항목을 배치합니다).)"

언급URL : https://stackoverflow.com/questions/53507553/wordpress-rest-api-reverse-proxy

반응형