193 viewsVPS301跳转 nginx
0

用nginx搭建的网站要更换域名要怎么设置301跳转?求个nginx规则,谢谢了!

Answered question
0
  1. server
  2.         {
  3.                 listen 80;
  4.                 server_name domain.com;
  5.                 return 301 https://$server_name$request_uri;
  6.         }
  7. server
  8.     {
  9.         listen 443 ssl http2;
  10.         server_name domain.com;
  11.         return 301 https://$server_name$request_uri;
  12.         ssl on;
  13.         ssl_certificate /usr/local/nginx/conf/ssl/domain.com/fullchain.cer;
  14.         ssl_certificate_key /usr/local/nginx/conf/ssl/domain.com/domain.com.key;
  15.         ssl_session_timeout 5m;
  16.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  17.         ssl_prefer_server_ciphers on;
  18.         ssl_ciphers “EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5”;
  19.         ssl_session_cache builtin:1000 shared:SSL:10m;
  20.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
  21.     }

将domain.com替换成你的域名,还有就是改ssl的crt文件和key文件的绝对路径(如果有ssl的话),如果重启nginx报错,注释掉

  1. ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
Edited answer

问题状态

  • 活跃
  • 阅读193 times
  • 回答数1 answer