HTTPS在Ubuntu服务器上不适用于Nginx和PHP的WordPress

zbdgwd5y  于 2024-01-05  发布在  PHP
关注(0)|答案(1)|浏览(137)

我试图配置一个WordPress网站与SSL配置.我安装了NGINX,PHP(7.4)和MySQL.
所以当我访问服务器的公共IP时,它成功加载了网站。我们也设置了DNS A记录。
假设URL是example.com,当我访问example.com时,它成功加载了网站,但没有HTTPS安全。我在sites-availablesites-enabled中创建了一个新的配置文件,并添加了以下内容。我删除了/etc/nginx.conf.d/中的配置文件

内容

  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. listen 443 ssl default_server;
  5. listen [::]:443 ssl default_server;
  6. ssl on;
  7. root /var/www/html/example.com;
  8. index index.php index.html index.htm;
  9. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
  10. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  11. server_name example.com <ip-of-the-vm>;
  12. location / {
  13. try_files $uri $uri/ /index.php?$args;
  14. }
  15. location ~ \.php$ {
  16. include snippets/fastcgi-php.conf;
  17. fastcgi_pass unix:/run/php/php7.4-fpm.sock;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. }
  20. }

字符串
我安装了certbot并使用以下命令创建了证书:

  1. sudo certbot --nginx -d example.com -d www.example.com


当我在浏览器中访问example.com时,它会加载网站但不安全。而且我还看到它重定向(它在浏览器的URL/搜索栏中显示服务器的公共IP。它正在重定向?)
x1c 0d1x的数据
修改NGINX配置文件。

  1. server {
  2. listen 80;
  3. server_name www.example.com example.com;
  4. return 301 https://$host$request_uri;
  5. }
  6. server {
  7. listen 443 ssl http2;
  8. server_name example.com;
  9. root /var/www/html/example.com;
  10. index index.php;
  11. # SSL parameters
  12. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  13. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  14. ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
  15. # log files
  16. access_log /var/log/nginx/example.com.access.log;
  17. error_log /var/log/nginx/example.com.error.log;
  18. location / {
  19. try_files $uri $uri/ /index.php?$args;
  20. }
  21. location ~ \.php$ {
  22. include snippets/fastcgi-php.conf;
  23. fastcgi_pass unix:/run/php/php7.4-fpm.sock;
  24. }
  25. }

cedebl8k

cedebl8k1#

  1. define('WP_SITEURL', 'http://example.com');
  2. define('WP_HOME', 'http://example.com');

字符串
添加了上面的wp-config.php并开始工作

相关问题