英文:
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 -> Has SSL certificate -> works perfectly
subdomain.domain.com -> Has SSL certificate covering the subdomain -> 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=<linodeIPAddressHere>
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 -> 大致如下:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
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]
<FilesMatch "\.(html|htm|js|css|php)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
</IfModule>
英文:
Maybe you need to edit .htaccess file in public folder of your domain ... If on APACHE -> Something like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
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]
<FilesMatch "\.(html|htm|js|css|php)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
</IfModule>
答案2
得分: -1
以下是翻译好的部分:
-
验证SSL证书安装:仔细检查子域名subdomain.domain.com的SSL证书安装情况。确保证书已正确安装在托管Laravel应用程序的服务器上。您可以使用在线SSL证书检查工具来验证安装并检查是否存在潜在问题。
-
检查虚拟主机配置:确保您的Web服务器的子域名虚拟主机配置已正确设置以处理SSL请求。在配置文件中,确保SSL证书和密钥路径已正确指定。
-
确认HTTPS监听器:验证您的Web服务器(例如,Apache或Nginx)是否配置为监听端口443以处理HTTPS请求。检查服务器配置以确保SSL模块已启用并且适当的虚拟主机配置存在。
-
混合内容问题:如果SSL证书已正确安装并且服务器已正确配置,另一个可能导致未显示小锁图标的常见问题是混合内容。这会在您的网页包含通过HTTP加载的资源(如图像、脚本或样式表)而不是HTTPS时发生。确保您页面上加载的所有资源都使用HTTPS URL,以避免此问题。
-
Laravel配置:检查您的Laravel应用程序的配置,确保它正确设置为HTTPS。在config/app.php文件中,验证url选项是否设置为https://subdomain.domain.com。此外,检查其他可能硬编码HTTP URL的配置文件,并将它们更新为使用HTTPS。
-
防火墙或负载均衡器设置:如果您使用防火墙或负载均衡器,请确保它已正确配置以将HTTPS流量转发到托管您的Laravel应用程序的正确服务器。检查设置以确保允许端口443并正确转发。
-
调试工具:使用调试工具和日志收集有关问题的更多信息。检查Web服务器的错误日志、Laravel的日志(storage/logs/laravel.log)和任何其他相关日志,看它们是否提供有关特定错误或错误配置的线索。
通过执行这些步骤,您应该能够识别并解决阻止您安全访问子域名https://subdomain.domain.com的问题。
英文:
Here are a few suggestions to help you troubleshoot and resolve the issue:
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论