如何在Apache和Nginx中将Http重定向到Https

Http is popular protocol used to transfer web page data like HTML, Javascript, Image etc. HTTP is used between our browser like Chrome, Firefox, Edge, Internet Explorer and server like Apache, Nginx etc. HTTPS is secure version of HTTP and recently sites transition to the HTTPS. But what is a user try to access HTTP of our web site. We can redirect HTTP web sites to the HTTPS. Below you can find redirect ways for different web servers.

Http是流行的协议,用于传输HTML,Javascript,Image等网页数据。HTTP用于我们的浏览器(例如Chrome,Firefox,Edge,Internet Explorer和服务器,例如Apache,Nginx等)之间。HTTPS是HTTP和最近站点的安全版本过渡到HTTPS。 但是,什么是用户尝试访问我们网站的HTTP。 我们可以将HTTP网站重定向到HTTPS。 在下面,您可以找到用于不同Web服务器的重定向方式。

阿帕奇 (Apache)

Apache is very popular web server which is number 1 in internet. We can use HTTP 301 Redirect status code for this like below. But as we can see we need to enable RewriteEngine too.

Apache是​​非常流行的Web服务器,在互联网上排名第一。 我们可以像下面这样使用HTTP 301重定向状态代码。 但是正如我们看到的,我们也需要启用RewriteEngine

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Nginx的 (Nginx)

Nginx is another popular web server which gains momentum in last years. We can use following server configuration in order to redirect HTTP to HTTPS. We will use HTTP 301 Redirect status code with return option. Other part of the configuration is just example.

Nginx是另一种流行的Web服务器,近年来发展势头强劲。 我们可以使用以下server配置来将HTTP重定向到HTTPS。 我们将使用带有return选项的HTTP 301重定向状态代码。 配置的其他部分仅是示例。

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
LEARN MORE  How To Generate and Configure Htpasswd For Apache?
了解更多信息如何为Apache生成和配置Htpasswd?

翻译自: https://www.poftut.com/how-to-redirect-http-to-https-in-apache-nginx/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值