我在Laravel Web应用程序上实现了google api,只有用户在域名前手动输入https(这意味着我已加密SSL证书)时,地理位置才能起作用。我已经尝试过在这里发布的各种解决方案,在不同的在线教程中以及在数字海洋社区论坛上,都没有得到我想要的简单结果。
目前如何工作:
我当前的nginx配置代码:
server {
listen 80;
root /var/www/domain/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name www.domain.com domain.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我尝试过的事情:
我得到的结果是
任何帮助将不胜感激,在此先感谢您!
解决方案
因此,感谢这篇Nginx git server returns error 500的相关文章,我得以将配置文件修改为如下所示:
server {
listen 80;
server_name www.domain.com domain.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443 ssl;
server_name www.domain.com domain.com;
root /var/www/domain/public;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
希望这有助于其他人在LEMP服务器上运行的Laravel项目中工作:)