无法通过HTTPS访问Laravel

huangapple go评论80阅读模式
英文:

Cannot Access Laravel via HTTPS

问题

我在使用https访问我的网站时遇到了问题。以下是布局:

domain.com -> 有SSL证书 -> 完美工作

subdomain.domain.com -> 有覆盖子域的SSL证书 -> 问题 - 这个子域有一个A DNS记录,指向托管我的Laravel的Linode服务器IP地址

访问 http://subdomain.domain.com/ 可以工作,但没有显示锁图标。

访问 https://subdomain.domain.com/ 报错 无法访问,并且Laravel显示 无效请求(不支持的SSL请求) 错误。

这是我的 ENV 配置:

APP_ENV=production
APP_DEBUG=true
APP_URL=https://subdomain.domain.com

SERVER_PORT=443
SERVER_HOST=<linodeIPAddressHere>

boot() 方法中的 AppServiceProvider.php 里没有任何内容,我已经尝试了许多解决方案。我的Linode防火墙允许端口443的入站和出站流量,SSL证书已经完全安装,可以通过SSL检查网站确认。我卡在这里,我愿意排查任何问题,因为我会一直努力找到解决方法。

更新:

我正在运行 Laravel Jetstream 9.52.9,PHP 8.1.2-1 Ubuntu 20.04 LTS。

我没有安装Nginx或任何Apache相关的东西。只安装了Composer、PHP、git和项目以使其运行起来。

最终更新
我的错误是没有安装Nginx,试图绕过问题,只是为了让原型工作。更好的方法是按照标准流程进行配置,这样会容易得多。

英文:

I am having an issue accessing my site using https. Here is the layout

domain.com -&gt; Has SSL certificate -&gt; works perfectly

subdomain.domain.com -&gt; Has SSL certificate covering the subdomain -&gt; ISSUES - This subdomain has an A DNS record looking at a Linode Server IP address hosting my Laravel

Accessing http://subdomain.domain.com/ works but shows no padlock

Accessing https://subdomain.domain.com/ throws cannot be reached with Laravel giving the Invalid request (Unsupported SSL request) error

Here is my ENV

APP_ENV=production
APP_DEBUG=true
APP_URL=https://subdomain.domain.com

SERVER_PORT=443
SERVER_HOST=&lt;linodeIPAddressHere&gt;

There is nothing in the boot() AppServiceProvider.php and I have tried many solutions. My Linode Firewall is allowing port 443 inbound and outbound, the SSL certificate is 100% installed using SSL checker websites. I'm stuck here. I'm happy to troubleshoot anything as I'll be working on this until I can find a fix.

UPDATE

I am running Laravel Jetstream 9.52.9, PHP 8.1.2-1 Ubuntu 20.04 LTS

I don't have Nginx installed or anything Apache wise. Just installed Composer, PHP, git and the project to get it up and running

Final Update
My mistake was not installing Nginx and trying to cut the corner just to get the prototype to work. It is much easier to do it properly.

答案1

得分: 0

以下是翻译后的内容:

也许你需要编辑你域名的 public 文件夹中的 .htaccess 文件... 如果使用 APACHE -> 大致如下:

&lt;IfModule mod_rewrite.c&gt;
&lt;IfModule mod_negotiation.c&gt;
    Options -MultiViews -Indexes
&lt;/IfModule&gt;

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

# 处理授权头
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# 重定向末尾的斜杠,如果不是文件夹...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# 将请求发送到前端控制器...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

&lt;FilesMatch &quot;\.(html|htm|js|css|php)$&quot;&gt;
    FileETag None
    &lt;IfModule mod_headers.c&gt;
        Header unset ETag
        Header set Cache-Control &quot;max-age=0, no-cache, no-store, must-revalidate&quot;
        Header set Pragma &quot;no-cache&quot;
        Header set Expires &quot;Wed, 12 Jan 1980 05:00:00 GMT&quot;
    &lt;/IfModule&gt;
&lt;/FilesMatch&gt;

</IfModule>

英文:

Maybe you need to edit .htaccess file in public folder of your domain ... If on APACHE -> Something like this:

&lt;IfModule mod_rewrite.c&gt;
&lt;IfModule mod_negotiation.c&gt;
    Options -MultiViews -Indexes
&lt;/IfModule&gt;

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

&lt;FilesMatch &quot;\.(html|htm|js|css|php)$&quot;&gt;
    FileETag None
    &lt;IfModule mod_headers.c&gt;
        Header unset ETag
        Header set Cache-Control &quot;max-age=0, no-cache, no-store, must-revalidate&quot;
        Header set Pragma &quot;no-cache&quot;
        Header set Expires &quot;Wed, 12 Jan 1980 05:00:00 GMT&quot;
    &lt;/IfModule&gt;
&lt;/FilesMatch&gt;

</IfModule>

答案2

得分: -1

以下是翻译好的部分:

  1. 验证SSL证书安装:仔细检查子域名subdomain.domain.com的SSL证书安装情况。确保证书已正确安装在托管Laravel应用程序的服务器上。您可以使用在线SSL证书检查工具来验证安装并检查是否存在潜在问题。

  2. 检查虚拟主机配置:确保您的Web服务器的子域名虚拟主机配置已正确设置以处理SSL请求。在配置文件中,确保SSL证书和密钥路径已正确指定。

  3. 确认HTTPS监听器:验证您的Web服务器(例如,Apache或Nginx)是否配置为监听端口443以处理HTTPS请求。检查服务器配置以确保SSL模块已启用并且适当的虚拟主机配置存在。

  4. 混合内容问题:如果SSL证书已正确安装并且服务器已正确配置,另一个可能导致未显示小锁图标的常见问题是混合内容。这会在您的网页包含通过HTTP加载的资源(如图像、脚本或样式表)而不是HTTPS时发生。确保您页面上加载的所有资源都使用HTTPS URL,以避免此问题。

  5. Laravel配置:检查您的Laravel应用程序的配置,确保它正确设置为HTTPS。在config/app.php文件中,验证url选项是否设置为https://subdomain.domain.com。此外,检查其他可能硬编码HTTP URL的配置文件,并将它们更新为使用HTTPS。

  6. 防火墙或负载均衡器设置:如果您使用防火墙或负载均衡器,请确保它已正确配置以将HTTPS流量转发到托管您的Laravel应用程序的正确服务器。检查设置以确保允许端口443并正确转发。

  7. 调试工具:使用调试工具和日志收集有关问题的更多信息。检查Web服务器的错误日志、Laravel的日志(storage/logs/laravel.log)和任何其他相关日志,看它们是否提供有关特定错误或错误配置的线索。

通过执行这些步骤,您应该能够识别并解决阻止您安全访问子域名https://subdomain.domain.com的问题。

英文:

Here are a few suggestions to help you troubleshoot and resolve the issue:

  1. Verify SSL Certificate Installation: Double-check the SSL certificate installation for the subdomain subdomain.domain.com. Ensure that the certificate is installed correctly on the server hosting the Laravel application. You can use online SSL certificate checkers to verify the installation and check for any potential issues.

  2. Check Virtual Host Configuration: Ensure that your web server's virtual host configuration for the subdomain is correctly set up to handle SSL requests. In the configuration file, make sure that the SSL certificate and key paths are specified correctly.

  3. Confirm HTTPS Listener: Verify that your web server (e.g., Apache or Nginx) is configured to listen on port 443 for HTTPS requests. Check the server configuration to ensure that the SSL module is enabled and that the appropriate virtual host configuration is present.

  4. Mixed Content Issue: If the SSL certificate is installed correctly and the server is properly configured, another common issue that can cause the padlock to not appear is mixed content. This occurs when your web page includes resources (such as images, scripts, or stylesheets) loaded over HTTP instead of HTTPS. Make sure that all the resources loaded on your page are using HTTPS URLs to avoid this issue.

  5. Laravel Configuration: Check your Laravel application's configuration to ensure that it is correctly set up for HTTPS. In the config/app.php file, verify that the url option is set to https://subdomain.domain.com. Additionally, check any other configuration files where you might have hard-coded HTTP URLs and update them to use HTTPS.

  6. Firewall or Load Balancer Settings: If you are using a firewall or a load balancer, make sure that it is correctly configured to forward HTTPS traffic to the correct server hosting your Laravel application. Check the settings to ensure that port 443 is allowed and forwarded correctly.

  7. Debugging Tools: Utilize debugging tools and logs to gather more information about the issue. Check the web server's error logs, Laravel's logs (storage/logs/laravel.log), and any other relevant logs to see if they provide any clues about the specific error or misconfiguration.

By going through these steps, you should be able to identify and resolve the issue preventing you from accessing your subdomain https://subdomain.domain.com securely.

huangapple
  • 本文由 发表于 2023年6月18日 19:57:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定