我最近買了一個我想試用的SSL證書。我也是第一次創建了VPS服務器,經過許多艱苦和憤怒的管理,我成功地在Ubuntu 14.04上安裝了LEMP和NGINX,並且還安裝了SSL證書。我的網站是wknet.se。NGINX http://example.com到https://www.example.com重寫,怎麼樣?
現在,我想重寫網址:
----------------------------------------------------------------
| From | To |
----------------------------------------------------------------
| http://wknet.se | https://www.wknet.se |
| http://wknet.se/index.php | https://www.wknet.se |
| http://www.wknet.se/index.php | https://www.wknet.se |
| wknet.se | https://www.wknet.se |
| wknet.se/index.php | https://www.wknet.se |
| www.wknet.se/index.php | https://www.wknet.se |
| https://wknet.se | https://www.wknet.se |
| https://wknet.se/index.php | https://www.wknet.se |
----------------------------------------------------------------
許多試驗和錯誤,幾個毀滅性小時,我只有2重寫留給修復後:
----------------------------------------------------------------
| From | To |
----------------------------------------------------------------
| https://wknet.se | https://www.wknet.se |
| https://wknet.se/index.php | https://www.wknet.se |
----------------------------------------------------------------
現在,我不知道如何解決它們!我已經Google和谷歌搜索,我已經測試了幾個很好的NGINX重寫規則,但我還沒有弄明白。
這是我第一次在NGINX上使用SSL,重寫規則等。
現在,這是我的服務器設置什麼樣子的wknet.se:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://www.wknet.se$request_uri;
}
server {
listen 443 ssl;
server_name www.wknet.se;
root /var/www/wknet.se/html;
index index.php index.html index.htm;
ssl_certificate /etc/nginx/ssl/SSL.CRT;
ssl_certificate_key /etc/nginx/ssl/KEY.KEY;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
ssl_prefer_server_ciphers on;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location/{
try_files $uri $uri/ =404;
}
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location = /index {
rewrite ^/index\.(php)$ https://www.wknet.se/ permanent;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
error_log off;
log_not_found off;
}
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
log_not_found off;
expires 365d;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|png|gif|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~* \.(7z|ai|class|css|csv|ejs|eps|flv|html?|jar|jpe?g|js|json|lzh|m4a|m4v|mov|mp3|pdf|pict|pls|ps|psd|swf|tiff?|txt|webp)$ {
access_log off;
log_not_found off;
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
}
如果有人可以幫助我我會很開心!此外,如果有人在我的服務器設置上有提示來進行一些改進,它也會幫助很多人,因爲我不知道我是否做得正確!
謝謝!
非常感謝你的那個@kchan,它的工作完美:)它順利重定向。 我複製了一切,並將其更改爲符合我的需要,並將其複製到我在服務器上的其他站點。但問題在於它總是重定向到虛擬服務器。 工作的唯一鏈接是[https://www.webkreativ.hr](https://www.webkreativ.hr)和[https://webkreativ.hr](https://webkreativ.hr)。 如果您輸入webkreativ.hr或[www.webkreativ.hr](http://www.webkreativ.hr),您將被重定向到[https://www.wknet.se](https:// www .wknet.se)。我究竟做錯了什麼? – damircalusic 2014-09-20 21:17:01
你應該有一個默認的服務器模塊,它是所有請求的「catchall」。通常你會將* server_name *設置爲* _ *,並在該塊中將所有請求重定向到任何你想要的url。我會檢查你的服務器nginx配置,看看默認的服務器塊重定向到什麼。請參閱nginx文檔以獲取「全部捕獲」服務器塊的示例:http://nginx.org/en/docs/http/server_names.html – kchan 2014-09-21 00:41:20
這裏您可以看到 - > [nginx.conf]的設置( https://www.wknet.se/nginx/nginx.conf.txt)。在這裏你可以看到 - > [wknet.se](https://www.wknet.se/nginx/wknet.se.txt)的設置。在這裏你可以看到 - > [webkreativ.hr](https://www.wknet.se/nginx/webkreativ.hr.txt)的設置。如果你能幫助我進一步,我會非常高興。 – damircalusic 2014-09-21 15:04:19