【问题标题】:How to redirect google VM external ip address to HTTPS in django with Debial and Apache?如何使用 Debial 和 Apache 在 django 中将 google VM 外部 IP 地址重定向到 HTTPS?
【发布时间】:2019-10-08 17:24:58
【问题描述】:

我已经使用 certbot 成功安装了 SSL 证书,并且可以在我的 google cloud 上的 debian 和 apache linux 虚拟机上进行加密。

该域已通过 HTTPS 成功保护。

虽然在直接访问外部 IP 地址时,我仍然会得到一个不安全的网站版本。 如何将 ip 直接重定向到使用 APACHE 设置的 HTTPS 版本,并将“domain.com”重定向到 -->> HTTPs:www.domain.com 。

我尝试像在 PHP 中一样将端口 80 和 443 重新路由到 HTTPS 版本,但没有任何运气,如下所示: How to redirect from www to https www with htacces?

在我的 000-default.conf 中:

<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.bracketline.com [OR]
RewriteCond %{SERVER_NAME} =localhost
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} 
[END,NE,R=permanent]
</VirtualHost>

在我的 000-default-le-ssl.conf 我有:

<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerName localhost
ServerAdmin webmaster@localhost

Alias /static /var/www/static-root
<Directory /var/www/static-root>
 Require all granted
 </Directory>
Alias /media /var/www/media-root
<Directory /var/www/media-root>
 Require all granted
</Directory>
<Directory /var/www/venv/src/cfehome>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess cfehome python-            
path=/var/www/venv/src/:/var/www/venv/lib/python3.5/site-packages
WSGIProcessGroup cfehome
WSGIScriptAlias / /var/www/venv/src/cfehome/wsgi.py

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAlias www.bracketline.com
SSLCertificateFile 
/etc/letsencrypt/live/www.bracketline.com/fullchain.pem
SSLCertificateKeyFile 
/etc/letsencrypt/live/www.bracketline.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

我不确定这东西是如何工作的,如果可以提供详细的博客或教程,那将有很大的帮助。提前谢谢!

【问题讨论】:

    标签: django apache google-cloud-platform debian virtual-machine


    【解决方案1】:

    首先通过键入apachectl -S 确定您实际使用的.conf 文件(这适用于基于Debian 的操作系统)。

    接下来编辑文件,它应该看起来很相似:

    <VirtualHost *:80> 
      ServerName example.com
      ServerAlias www.example.com
    
      Redirect permanent / https://example.com/
    </VirtualHost>
    
    <VirtualHost *:443>
      ServerName example.com
      ServerAlias www.example.com
    
      Protocols h2 http/1.1
    
      # SSL Configuration
    
      # Other Apache Configuration
    
    </VirtualHost>
    

    一般有几个教程如何配置 HTTP 到 HTTPS 重定向:

    还有一些有趣的讨论Why is my Apache VirtualHost directing to the wrong VirtualHost

    最后 - 这是another SO discussion on that topic that has an accepted answer

    这些只是最近(最多 2 年)的示例,可以帮助您,如果它们无法回答您的问题,还有很多示例。

    【讨论】:

      猜你喜欢
      • 2013-04-06
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 2016-01-09
      • 2011-04-19
      • 2021-03-25
      • 2020-04-07
      相关资源
      最近更新 更多