ssl - 服务器在使用 https [nginx] 时显示 404

标签 ssl nginx server

如有任何帮助,我们将不胜感激。

我已经收到来自 letsencrypt 的 SSL 证书,并且正在尝试为我的服务器同时支持 HTTP 和 HTTPS。证书很好,但在尝试使用 https 访问我的网站时出现 404。这是我的配置文件:

server {
  server_name my.domain.org;

  root /var/www/my.domain.org/htdocs;
  index index.php index.html index.html;

  server_name my.domain.org;
  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  # Add trailing slash to */wp-admin requests.
  rewrite /wp-admin$ $scheme://$host$uri/ permanent;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # # With php5-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  location = /favicon.ico {
    access_log off;
    log_not_found off;
  }

  location = /robots.txt {
    access_log off;
    log_not_found off;
  }

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

server {
  listen 443;

  ssl on;
  ssl_certificate /etc/letsencrypt/live/my.domain.org/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/my.domain.org/privkey.pem;

  server_name my.domain.org;
  access_log /var/log/nginx/nginx.vhost.access.log;
  error_log /var/log/nginx/nginx.vhost.error.log;

  location / {
    root /var/www/my.domain.org/htdocs;
    index index.php index.html index.html;
  }
}

最佳答案

https 的配置与 http 没有区别。

因此,只需复制相同的 http 配置并添加 ssl 特定部分:

# https
server {
  listen 443 ssl; 
  # for http2 support uncomment line bellow and comment line above
  # listen 443 ssl http2;  

  ssl on;
  ssl_certificate /etc/letsencrypt/live/my.domain.org/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/my.domain.org/privkey.pem;

  server_name my.domain.org;

  root /var/www/my.domain.org/htdocs;
  index index.php index.html index.html;

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

  rewrite /wp-admin$ $scheme://$host$uri/ permanent;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  location = /favicon.ico {
    access_log off;
    log_not_found off;
  }

  location = /robots.txt {
    access_log off;
    log_not_found off;
  }

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

#http
server {
  listen 80;
  root /var/www/my.domain.org/htdocs;
  index index.php index.html index.html;

  server_name my.domain.org;
  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  rewrite /wp-admin$ $scheme://$host$uri/ permanent;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  location = /favicon.ico {
    access_log off;
    log_not_found off;
  }

  location = /robots.txt {
    access_log off;
    log_not_found off;
  }

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

关于ssl - 服务器在使用 https [nginx] 时显示 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41432285/

相关文章:

mysql - 远程连接Mysql数据库

iis - IIS 6 上的 SSL 配置问题

c# - TLS 1.2 错误 - 未提供客户端证书。在 ClientCredentials 中指定客户端证书

c# - 在 HttpClient 中使用受信任的根证书颁发机构进行服务器证书验证

amazon-web-services - 为同一服务器使用多个证书

ubuntu - Nginx 错误未写入我的 error_log 指令

django - 在 docker 上使用 nginx gunicorn 配置 django

nginx - 如何干燥 nginx 配置

java - 我如何在其他位置(如/instanceDirectory)中创建 solr 核心实例目录?

flash - 命令中的 ipconfig 它显示 "ipconfig is not recognized as internal or external command""