
내 사이트는 IP 1.2.3.4에 있습니다.
내 도메인 공급자에는 1.2.3.4를 가리키는 onesite.com과 anothersite.com이 모두 있습니다.
Nginx에는 두 개의 사이트가 구성되어 있습니다.
server {
listen 1.2.3.4:80;
server_name www.oneserver.com;
rewrite ^(.*) http://onserver.com$1 permanent;
}
server {
listen 1.2.3.4:80;
server_name onserver.com;
location / {
fastcgi_pass 127.0.0.1:8878;
[..]
그리고:
server {
listen 1.2.3.4:80;
server_name myapp.anotherserver.com;
location / {
fastcgi_pass unix:/tmp/myapp.sock;
[..]
myapp.anotherserver.com에 액세스하면 oneserver.com으로 리디렉션됩니다.
도움이 필요하세요?
답변1
user186340
지적한 대로 구성 스니펫은 괜찮아 보이고 myapp.anotherserver.com
포트 액세스는 80
제공한 세 번째 블록에서 제공되어야 합니다. 설명대로 작동하지 않으면 로드되지 않았기 때문일 수 있습니다.
- 여기에 표시된 모든 구성이 nginx에 의해 발견/로드되었는지 확인하세요.
nginx -t
구성을 검증하는 데 사용- 보낼 때 오류 로그를 모니터링하십시오.
HUP
신호팝업되는 오류 메시지를 확인하기 위해 nginx 마스터 프로세스에 - nginx v1.9.2+를 사용하는 경우 다음을 사용하고 싶을 수도 있습니다.
nginx -T
로드된 구성을 표준 출력으로 덤프하려면
다음 사항이 모두 정상이라면 실제로 사용하는 구성과 비교하여 표시된 구성을 수정했을 것입니다.
답변2
문제는 Nginx가 기본 서버를 선택하고 명시적으로 정의된 서버 없이 모든 요청에 이를 제공한다는 것입니다. 내 해결 방법은 아무 작업도 수행하지 않는 기본 서버를 정의하는 것입니다.
# This just prevents Nginx picking a random default server if it doesn't know which
# server block to send a request to
server {
# You can add 443/ssl if you need to
listen 80 default_server;
server_name _;
access_log off; log_not_found off;
# "I'm a teapot", effectively "go away" https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error
# Code 403 (forbidden), 410 (gone) or 501 (not implemented) is probably a better choice https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error
return 418;
}