nginx 抱怨在端口 80 上的“listen ... ssl”指令中定义了“ssl_certificate”

nginx 抱怨在端口 80 上的“listen ... ssl”指令中定义了“ssl_certificate”

尝试重新启动 nginx 时,出现错误nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive。我正在使用 SSL,但错误发生在我网站的 nginx 配置文件的第 54 行 - 第二个server {是,目的是将 HTTP 重定向到 HTTPS。我的配置文件如下,用 example.com 代替我的实际域名。

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
#

# Default server configuration
#

server {

        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /var/www/default/certificate.crt;
        ssl_certificate_key /var/www/default/key.pem;

        root /var/www/default;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;
        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }

        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { log_not_found off; }

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                try_files $fastcgi_script_name =404;
                include fastcgi_params;
                fastcgi_pass  unix:/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param DOCUMENT_ROOT  $realpath_root;
                fastcgi_param SCRIPT_FILENAME   $realpath_root$fastcgi_script_name;
        }
}

server {
        listen 80;
        listen [::]:80;
        server_name example.com www.example.com;
        return 301 https://example.com;
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

我对此还只是个菜鸟,所以如果我说错了什么,请见谅,我很乐意按照要求添加详细信息。提前致谢!

相关内容