在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
从nginx的官方文档 documentation, 正确的nginx https 301跳转到带www域名方法的方法如下: HTTP 301跳转到带www域名方法
复制代码 代码如下: server {
listen 80; server_name example.org; return 301 http://www.example.org$request_uri; } server { HTTPS 301跳转到带www域名方法
复制代码 代码如下: server { listen 80; server_name www.domain.com; // $scheme will get the http protocol // and 301 is best practice for tablet, phone, desktop and seo return 301 $scheme://domain.com$request_uri; } server { listen 80; server_name domain.com; // here goes the rest of your config file // example location / { rewrite ^/cp/login?$ /cp/login.php last; // etc etc... } } 要先用 nginx -v 命令检查你所说使用的nginx的版本. 下面是对于旧版本的nginx301跳转到带www域名方法从www.ksharpdabu.info 跳转到 ksharpdabu.info
复制代码 代码如下: server {
server_name www.domain.com; rewrite ^(.*) http://domain.com$1 permanent; } server {
从ksharpdabu.info 跳转到 www.ksharpdabu.info
复制代码 代码如下: server {
server_name domain.com; rewrite ^(.*) http://www.domain.com$1 permanent; } server {
复制代码 代码如下: server {
server_name www.google.com; rewrite ^(.*) http://google.com$1 permanent; } server { listen 80; server_name google.com; index index.php index.html; #### # now pull the site from one directory # root /var/www/www.google.com/web; # done # location = /favicon.ico { log_not_found off; access_log off; } }
复制代码 代码如下: server {
#listen 80 is default server_name www.example.com; return 301 $scheme://example.com$request_uri; } server {
下面包含了http和https的。同一个服务器。
复制代码 代码如下: server { listen 80; listen 443 ssl; server_name www.example.com; return 301 $scheme://example.com$request_uri; } server { $scheme 变量只会包含http 如果你的服务器只监听80端口(默认是80端口)同时监听的选项中不含ssl关键字 . 不适用这个变量,就不能获得你所想的要的跳转结果。 将所有http强制跳到https, SSL (personal config on UNIX with IPv4, IPv6, SPDY, ...): 复制代码 代码如下: # # Redirect all www to non-www # server { server_name www.example.com; ssl_certificate ssl/example.com/crt; ssl_certificate_key ssl/example.com/key; listen *:80; listen *:443 ssl spdy; listen [::]:80 ipv6only=on; listen [::]:443 ssl spdy ipv6only=on; return 301 https://example.com$request_uri; # return 301 https://example.com$request_uri; # # rest goes here... |
请发表评论