nginx 업스트림을 사용하여 워드 프레스 상수
Nginx를 실행하는 server1이 모든 "/" 위치를 server2에 전달하고 "/api" 등을 server1에 유지하는 상황이 발생했습니다.이것은 또한 SSL을 계속해서 작동시키기 위한 것입니다.WP URL을 http://test.example.com 에서 https://example.com 으로 이동하려고 하면 첫 페이지가 올바르게 로드되지만 로드됩니다.wp-admin
리디렉션이 너무 많습니다.
서버1 Nginx:
업스트림 webapp_url {서버 IP:80;} 서버 {443 ssl 듣기;server_name www.example.com example.com ;access_log /var/log/nginx/example.log; ssl_certificate /etc/nginx/ssl/example.crt;ssl_certificate_key /etc/nginx/ssl/server.키;ssl_암호 RC4하이:!aNULL:!MD5;SSL_prefer_server_ciphers on; 위치/파일/{뿌리/가정;access_log off;expires max;if ($request_filename!~*^.*?\.(jpg)|(png)|(gif)|(pdf){add_header Content-Disposition: "$request_filename";}} 위치 / {# proxy_pass http://site_url/;proxy_http_version 1.1;proxy_set_header 업그레이드 $http_upgrade;proxy_set_header 연결 '업그레이드';proxy_set_header Host $host;proxy_set_header X-Forwarded-$remote_addr인 경우;proxy_set_header X-Forwarded-Proto https;proxy_cache_bypass $http_upgrade;proxy_set_header X-예 "1";proxy_pass http://webapp_url/;}
이것은 다른 서버를 정상적으로 로드하고 홈페이지를 통해 모든 작업을 링크합니다(관리자에서 변경할 수 없기 때문에 혼합된 내용 경고에도 불구하고). WPsiteurl
그리고.home
둘 다 새 주소로 설정되어 있습니다.
서버2 Nginx:
서버 {#443 ssl 듣기;듣기 80;server_name example.com test.example.com ;client_max_body_size 30M;error_log /var/log/wordpress/error.log 정보;위치 / {루트/홈/워드프레스;try_files $uri $uri/ /index.php?q=$request_uri;index index.php index.htm;} #ssl_certific레이트 /etc/nginx/ssl/example.crt;#ssl_certific_키 /etc/nginx/ssl/example키;#ssl_암호 RC4:하이:!aNULL:!MD5;#ssl_prefer_server_ciphers on; error_page 404/404. html;위치 = /404. html {root /usr/share/nginx/html;} error_page 500502 503 504/50x.html;위치 = /50x.html {root /usr/share/nginx/html;} #위치 ~ \. php$ {루트/홈/워드프레스;fastcgi_pass unix:/var/run/ php5-fpm. sock;fastcgi_index 인덱스.php;fastcgi_param SCRIPT_FILname $document_root$fastcgi_script_name;fastcgi_params 포함.}}
/wp-admin/
는 무한 리디렉션(동일한 URL로)을 시작합니다.요로 wp-config.php
한:
정의('WP_HOME', 'https://example.com ');정의를 내리다WP_SITEURL', 'https://example.com ');
wp-admin
그렇지 . 그렇지 않으면 로 리디렉션됩니다.https
동일한 URL의 버전입니다. 당신과 같은 상황에서는 리디렉션 루프가 발생합니다.
워드프레스에 연결이 안전하다고 말해야 합니다.
서버 1에서 적절한 헤더를 다음과 같이 설정하는 것을 알 수 있습니다.
proxy_set_header X-Forwarded-Proto $scheme;
의 경우, ()의 값이$scheme
에 유선 연결되어 있습니다.https
).
.HTTPS
수 값,값:on
.
는 은 A 를 됩니다를 통해 .map
2)항버 2에서):
map $http_x_forwarded_proto $https_flag {
default off;
https on;
}
server {
...
}
()map
됩니다 됩니다.http
록 . 바로 위에 배치하시면 됩니다.server
위와 같은 블록.자세한 내용은 이 문서 참조)
외에 합니다를 더 추가합니다.fastcgi_param
HTTPS
WordPress에 대한 매개 변수(서버 2에서):
location ~ \.php$ {
...
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS $https_flag;
...
}
1단계.
- 필요한 PHP 버전을 활성화하고 서버에 설치합니다.
2단계.
sudo yum install php-cli php-pdo php-fpm php-mysqlnd
3단계.
sudo systemctl start php-fpm
4단계.
sudo systemctl enable php-fpm
마지막으로 Nginx 구성 복사
server {
root /path/to/your/wordpress;
index index.php index.html index.htm;
server_name site.com www.site.com;
add_header X-Frame-Options SAMEORIGIN;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # path might differ from OS to OS
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
언급URL : https://stackoverflow.com/questions/39338854/wordpress-constant-redirect-with-nginx-upstream
'programing' 카테고리의 다른 글
git push 명령에서 사용자 이름 및 암호 (0) | 2023.10.16 |
---|---|
MySQL에서 대문자를 확인하는 방법? (0) | 2023.10.16 |
SQL에서 매핑 값을 선택하시겠습니까? (0) | 2023.10.16 |
열 이름 MySQL Workbench MariaDB (0) | 2023.10.16 |
C에서 댓글을 #정의할 수 있습니까? (0) | 2023.10.16 |