2017-12-16 7 views
0

내가 왜 conflicting server name 예외인지 알 수 없습니다.nginx에서 서버 이름이 충돌 함

접두어에 WWW과 함께 요청을 수락합니다.

return 301 https://$server_name$request_uri;은 비 https 요청을 https로 보내야합니다.

이 예외를 해결하는 방법을 알려주세요.

Nginx.conf

server { 
    listen  80 ; 
    server_name myApp.co www.myApp.co; 

    root /home/deployer/workspace/myApp-web/dist; 
    error_log /var/log/nginx/myApp_web_error.log warn; 
    access_log /var/log/nginx/myApp_web_access.log; 
    listen 443 ssl; 
    listen [::]:443 ssl; 

    ssl_certificate /etc/nginx/ssl/myApp_co.bundled.crt; 
    ssl_certificate_key /etc/nginx/ssl/myApp.key; 
    large_client_header_buffers 4 4800k; 


    location/{ 
     try_files $uri $uri/ /index.html ; # make HTML5 workable 
     gzip on; 
     gzip_static on; 
     gzip_min_length 1k; 
     gzip_comp_level 6; 
     gzip_types application/javascript text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; 
     gzip_vary off; 
     gzip_disable "MSIE [1-6]\."; 
    } 

    location /api/v1 { 
     proxy_pass http://localhost:7617/api/v1/; 
    } 
} 

server { 
    listen  80; 
    server_name myApp.co www.myApp.co; 
    return 301 https://$server_name$request_uri; 
} 

당신은 동일한 포트에서 동일한 서버 _ 듣고 두 개의 서버 블록을 가질 수 없습니다

2017/12/05 06:54:42 [warn] 6059#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored 
    2017/12/05 06:54:42 [warn] 6059#0: conflicting server name "www.myApp.co" on 0.0.0.0:80, ignored 
    2017/12/05 06:55:05 [warn] 6089#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored 
    2017/12/05 06:55:05 [warn] 6089#0: conflicting server name "www.myApp.co" on 0.0.0.0:80, ignored 
    2017/12/05 06:55:06 [warn] 6093#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored 
+0

당신이 같은'listen'와'server' 블록과'server_name' 값이 - 거의 당신이보고있는 경고를 정의합니다. –

답변

1

예외 로그.

나는 첫 번째 서버 블록에 당신이 HTTPS 요청을 승인하려는 생각, 그래서 당신은 443

server { 
    listen  443; 
    server_name myApp.co www.myApp.co; 

    root /home/deployer/workspace/myApp-web/dist; 
    error_log /var/log/nginx/myApp_web_error.log warn; 
    access_log /var/log/nginx/myApp_web_access.log; 

    ssl_certificate /etc/nginx/ssl/myApp_co.bundled.crt; 
    ssl_certificate_key /etc/nginx/ssl/myApp.key; 
    large_client_header_buffers 4 4800k; 


    location/{ 
     try_files $uri $uri/ /index.html ; # make HTML5 workable 
     gzip on; 
     gzip_static on; 
     gzip_min_length 1k; 
     gzip_comp_level 6; 
     gzip_types application/javascript text/plain application/x- 
     javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; 
     gzip_vary off; 
     gzip_disable "MSIE [1-6]\."; 
    } 

    location /api/v1 { 
     proxy_pass http://localhost:7617/api/v1/; 
    } 
} 

server { 
    listen  80; 
    server_name myApp.co www.myApp.co; 
    return 301 https://$server_name$request_uri; 
}