각종 팁&정보를 나누는 곳입니다.
누군가에게 도움이 된다 싶으시면 언제라도 포스팅 :)
글 등록하기 | 내글 관리하기 | 연재글 | 보관함
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 1 / 57 pages
번호 제목 제목 조회 수 날짜날짜
683 비밀글 showttmp3 0 2008/08/01
682 [웹로그] 비밀글 파이어폭스 사용자 입맛에 고치기 0 2007/10/13
681 [웹로그] 비밀글 구글애드센스 광고형식 (작성중) 0 2007/10/19
680 [웹로그] 비밀글 테터툴즈 (+티스토리) 에서 mp3 추출하기 + 뽀나스 0 2007/11/03
679 [웹로그] 비밀글 내 블로그에 알맞는 수익도구는 무엇일까? 0 2007/11/05
678 [웹로그] 비밀글 쥬크온 1분 제한 제거 패치 0 2007/11/09
677 [웹로그] 비밀글 한메일, 네이버, 지메일 간 POP 보내고 받기 0 2007/11/11
676 [웹로그] 비밀글 블로거뉴스단에 가입하라. 0 2007/11/13
675 [웹로그] 비밀글 파이어폭스에서 mp3 재생이 안될 때 0 2007/11/17
674 [웹로그] 비밀글 웹 오피스 0 2007/11/18
673 [웹로그] 비밀글 구글 검색창 소스 [1] 0 2007/11/23
672 [웹로그] 비밀글 구글 애드센스 계정의 정확한 수익 알기 0 2007/11/23

해시태그 디렉터리

오늘의 핫게시물