각종 팁&정보를 나누는 곳입니다.
누군가에게 도움이 된다 싶으시면 언제라도 포스팅 :)
글 등록하기 | 내글 관리하기 | 연재글 | 보관함
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 16 / 57 pages
번호 제목 제목 조회 수 날짜날짜
503 [Apm] AutoSet(오토셋) vs ApmSetup7 294 2015/11/17
502 [웹 제작] 비밀글 Let's Encrypt 웹호스팅에 적용하기 0 2015/11/06
501 [브라우저] 브라우저 중복 즐겨찾기 정리 프로그램 135 2015/10/06
500 [Apm] [bitnami] 맥에서 APM 사용하기(비트나미 설치) 289 2015/09/22
499 [윈도우] .net Framework 3.5(닷넷프레임워크)이 깔리지 않을 때(0x80071a90)[Windows 8.1] 1202 2015/09/22
498 [윈도우] 윈도우 8.1 0x80070011 오류 458 2015/09/21
497 [기타] 인스타그램 pc버전 인스타넷 1316 2015/09/14
496 [기타] pc에서 인스타 하기 420 2015/09/14
495 [윈도우] hiberfil 파일 160 2015/09/10
494 [윈도우] .sit 파일 압축 풀기 1124 2015/09/06
493 [GitHub] github.io 페이지 만들기 파일 157 2015/09/04
492 [Apm] [Autoset] XE 설치 중 Session.auto_start 설정 : 불가능 문제 파일 515 2015/08/29

해시태그 디렉터리

오늘의 핫게시물