각종 팁&정보를 나누는 곳입니다.
누군가에게 도움이 된다 싶으시면 언제라도 포스팅 :)
글 등록하기 | 내글 관리하기 | 연재글 | 보관함
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 3 / 57 pages
번호 제목 제목 조회 수 날짜날짜
659 [기타] 주변기기 > 프린터 > hp Deskjet 600k 10941 2005/03/04
658 [기타] [mp3]구글에서 맘껏 받아 보아요 (by SelfEx>>) 9675 2005/03/05
657 [웹 제작] 보안관련 PHP 설정 조정 안내 (출처:http://byus.net) 7978 2005/03/07
656 [미디어/녹음·재생] 오디오 CD를 파일로 변환하기 9063 2005/03/08
655 [PHP] HTTP 접속하는 PHP 클래스 (by CRIZIN) 8707 2005/03/08
654 [PHP] http.php [1] 12144 2005/03/08
653 [브라우저] IE에서 XP SP2 적용 후에 썸네일이 안 보여요. 8294 2005/03/11
652 [미디어/녹음·재생] 소리바다 MP 안 깍이는 꼼수 (by vivian) [1] 9877 2005/04/06
651 [엑셀] 시트 간 이동 - ctrl + PageUp/Down 7603 2005/04/08
650 [기본] 테터툴즈 및 티스토리 도움말 링크 페이지 7303 2006/05/31
649 [웹로그] 테터툴즈 및 티스토리 도움말 링크 페이지 6513 2006/05/31
648 [메신저] MSN메신저 로그인 정보 지우기 9141 2006/08/08

해시태그 디렉터리

오늘의 핫게시물