각종 팁&정보를 나누는 곳입니다.
누군가에게 도움이 된다 싶으시면 언제라도 포스팅 :)
글 등록하기 | 내글 관리하기 | 연재글 | 보관함
nginx https redirect www to non-www
첨부파일 https://imweb.eond.com/webtip/398106
April 6, 2017 8.8kviews NGINX CENTOS


Hi i was config my nginx block to redirect all www to non-www, this is my config:


server {    listen       80;    server_name  mysite.com www.mysite.com;    return       301 https://mysite.com$request_uri; }
 server {    listen       443 ssl http2;    server_name  mysite.com;    root   /usr/share/nginx/html;     ssl on;    ssl_certificate /ssl/ssl-bundle.crt;    ssl_certificate_key /ssl/mysite.key;    ssl_session_cache shared:SSL:20m;    ssl_session_timeout 10m;    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    ssl_prefer_server_ciphers on;    ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:!DSS;    ssl_buffer_size 8k;    ssl_session_tickets off;     ssl_stapling on;    ssl_stapling_verify on;    ssl_trusted_certificate /ssl/ssl-trusted.crt;    resolver 8.8.8.8 8.8.4.4 valid=300s;    resolver_timeout 10s;     #add_header X-Content-Type-Options "nosniff";     location / {        index index.php index.html index.htm;    try_files $uri $uri/ /index.php?$uri&$args;    }     location /internal_data/ {        internal;        allow 127.0.0.1;        deny all;        }         location /library/ {        internal;        allow 127.0.0.1;        deny all;        }     location ~ \.php$ {    try_files $uri =404;    fastcgi_pass 127.0.0.1:9000;    fastcgi_index index.php;    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;    include fastcgi_params;    }     location ~* \.(?:ico|css|gif|jpe?g|js|png|svg|svgz|swf)(\?.+)?$ {        access_log              off;        log_not_found           off;        expires                 1y;    } 
location ~ \.(jpe?g|png|gif)$ {     valid_referers none blocked mysite.com *.mysite.com;     if ($invalid_referer) {        return   403;        }    } }


working fine just for non-www to https but not work from www to non-www,
this is result from curl -I http://www.mysite.com :

curl: (6) Couldn't resolve host 'www.mysite.com'

is there any iam miss?
thank you.


기존에 맨 위에 주석 처리된 부분으로 작업했었으나,

https://www.eond.com 에 대한 return이 적용이 되지 않아, 위 팁을 적용하여

주석줄 아래 코드로 변경해주었습니다.

# server {
#     listen       80;
#     server_name  eond.com www.eond.com;
#     root /home/eond/www;
#     location / {
#         return 301 https://eond.com$request_uri;
#     }
# }
server {
    listen       80;
    server_name  eond.com www.eond.com;
    return       301 https://eond.com$request_uri;
}


server {
   listen 443 ssl http2;
   server_name eond.com;
   root /home/eond/www;
   index index.php index.html index.htm;
   charset utf-8;

   # if ($http_host = "www.eond.com") {
   #  rewrite ^ https://eond.com$request_uri permanent;
   # }

   location / {
      try_files $uri $uri/ =404;
   }

   include snippets/well-known.conf;
   #include snippets/wp-rewrite.conf;
   include snippets/xe-rewrite.conf;

   location ~ \.php$ {
      fastcgi_pass unix:/run/php/pool.eond.sock;
      include snippets/fastcgi-php.conf;
      limit_req zone=antiddos burst=12 nodelay;
   }

   location ~* \.(jpe?g|png|gif|bmp|ico|svg|swf|flv|avi|wav|mp[34]|woff|ttf|s?css|less|js)$ {
      expires 15d;
      log_not_found off;
   }

   ssl_certificate /etc/letsencrypt/live/eond.com/fullchain.pem;
       ssl_certificate_key /etc/letsencrypt/live/eond.com/privkey.pem;
       ssl_trusted_certificate /etc/letsencrypt/live/eond.com/chain.pem;
       ssl_dhparam /etc/nginx/ssl/dhparam.pem;
       ssl_stapling on;
       ssl_stapling_verify on;
}

# server {
#  listen 80;
#  server_name www.eond.com;
#
#  location / {
#     return 301 https://eond.com$request_uri;
#     expires epoch;
#  }
#
#  include snippets/well-known.conf;
# }

server {
   listen 80;
   listen 443 ssl http2;
    server_name www.eond.com;
    return 301 $scheme://eond.com$request_uri;
}


코멘트 0
접기/펴기 | 댓글 새로고침
 
 
Total 683 articles in 25 / 57 pages
번호 제목 제목 조회 수 날짜날짜
395 [웹로그] IE와 FF에서 달리 보이는 png 5298 2007/11/22
394 [웹로그] TapiSrv 이란? 5304 2007/11/02
393 개인도메인 활용하기 (작성 중) 5396 2007/10/05
392 [윈도우] 윈도우 복원 방법 정리 5418 2014/02/15
391 [GitHub] Git 온라인 저장소 만들기 5441 2014/08/04
390 [웹로그] [프로디지 7.1 LT] 인터넷 녹음시 잡음이 심합니다. 5447 2007/10/29
389 [기본] 프로디지 7.1 LT 녹음하기 5465 2007/10/29
388 [기본] Adobe Fonts 폴더 활용하기 5486 2007/10/28
387 [웹로그] Bonjour Service 다시 한 번 알아보자. 파일 5499 2007/11/29
386 [웹로그] 블로그 수익의 종류 [2] 5541 2007/11/03
385 [기본] 입력폼과 이미지폼의 정렬은 어떻게 맞추나요? 5542 2007/11/09
384 [웹로그] Windows Live Writer 사용해보기 파일 [1] 5593 2007/11/18

해시태그 디렉터리

지금 이순간

오늘의 핫게시물