如果我直接访问https,它可以工作,但该站点仍然可以通过HTTP访问。如何将所有http强制转换为https?
我用过WordPress HTTPS plugin. 但它不会重定向到https。
我已使用以下配置nginx:
server {
listen xxx.x.xxx.xxx:80;
listen 127.0.0.1:80;
server_name mydomain.com;
root /var/www/html/mydomian.com/;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$args;
rewrite ^(.*)$ https://$http_host$request_uri redirect;
}
...
但这种重定向将导致无限循环。我安装了
CloudFlare Flexible SSL, 这表示可以解决无限循环,但仍然没有帮助。
有没有其他方法可以强制http重定向到https?
UPDATE
我的ssl块:
server {
listen xxx.x.xxx.xxx:443 ssl;
listen xxx.x.x.x:443 ssl;
server_name $hostname xxx.x.xxx.xxx;
ssl on;
ssl_certificate /etc/nginx/ssl.crt/server.crt.combined;
ssl_certificate_key /etc/nginx/ssl.key/server.key;
root /var/www/html;
index index.html index.htm index.php;
location ~^/~(?<userdir_user>.+?)(?<userdir_uri>/.*)?$ {
alias /home/$userdir_user/private_html$userdir_uri;
index index.html index.htm index.php;
autoindex on;
location ~ \\.php$ {
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
#try_files does not work after alias directive
if (!-f $request_filename) {
return 404;
}
fastcgi_param DOCUMENT_ROOT /home/$userdir_user/private_html;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
location ~ \\.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass unix:/usr/local/php55/sockets/webapps.sock;
fastcgi_pass 127.0.0.1:9000;
}
include /etc/nginx/nginx-info.conf;
include /etc/nginx/webapps.ssl.conf;
}
SO网友:Tunji
有几种方法可以在wordpress站点上启用https。
您需要更新网站URL,包括https 如果您可以访问仪表板
您还可以定义
WP_SITEURL
和
WP_HOME
在您的测试中
wp-config.php define( \'WP_SITEURL\', \'http://example.com.mytestdomain.com\' );
define( \'WP_HOME\', \'http://example.com.mytestdomain.com\' );
In relation to your nginx config:
可以使用if块,而不是将重写嵌套在基本位置
if ($host ~* ^example\\.com$) {
rewrite ^(.*)$ https://example.com$1 permanent;
}