Ubuntu Nginx上的SSL配置错误

Ubuntu Nginx上的SSL配置错误,ubuntu,ssl,nginx,lets-encrypt,Ubuntu,Ssl,Nginx,Lets Encrypt,我有两个不同的应用程序在两个不同的端口上运行。在端口80上运行的default_服务器应用程序成功地将所有HTTP请求重定向到HTTPS,但在端口18010上运行的第二个应用程序在配置Letsencrypt SSL时出错 这是服务器块文件- upstream cms-backend { server 127.0.0.1:8010 fail_timeout=0; } server { listen 18010; server_name ""; retu

我有两个不同的应用程序在两个不同的端口上运行。在端口80上运行的
default_服务器
应用程序成功地将所有
HTTP
请求重定向到
HTTPS
,但在端口
18010
上运行的第二个应用程序在配置Letsencrypt SSL时出错

这是服务器块文件-

upstream cms-backend {
            server 127.0.0.1:8010 fail_timeout=0;
    }

server {
  listen 18010;
  server_name "";
  return 301 https://$server_name:18010$request_uri;
}

server {
  # CMS configuration file for nginx, templated by ansible

  # Proxy to a remote maintanence page

  # error pages
  error_page 504 /server/server-error.html;
  error_page 502 /server/server-error.html;
  error_page 500 /server/server-error.html;

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

  include snippets/ssl-cabacademie.conf;
  include snippets/ssl-params.conf;


  # Prevent invalid display courseware in IE 10+ with high privacy settings
  add_header P3P 'CP="Open edX does not have a P3P policy."';

  # Nginx does not support nested condition or or conditions so
  # there is an unfortunate mix of conditonals here.

  server_name "";

  access_log /edx/var/log/nginx/access.log p_combined;
  error_log /edx/var/log/nginx/error.log error;

  # CS184 requires uploads of up to 4MB for submitting screenshots. 
  # CMS requires larger value for course assest, values provided 
  # via hiera.
  client_max_body_size 100M;

  rewrite ^(.*)/favicon.ico$ /static/images/favicon.ico last;


  # Blackholes an archive of python library files that instructors
  # may provide for sandboxed python problem types, the internal
  # directive will result in nginx emitting an nginx 404. Users
  # will not be redirected to the application 404 page.
  location ~* python_lib.zip {
    internal;
  }

# Common settings used across nginx configurations

# Disables server version feedback on pages and in headers
server_tokens off;

  location @proxy_to_cms_app {
        proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-For $remote_addr;

    # newrelic-specific header records the time when nginx handles a request.
    proxy_set_header X-Queue-Start "t=${msec}";

    proxy_set_header Host $http_host;

    proxy_redirect off;
    proxy_pass http://cms-backend;
  }

  location / {
        try_files $uri @proxy_to_cms_app;
  }

  # No basic auth security on the github_service_hook url, so that github can use it for cms
  location /github_service_hook {
    try_files $uri @proxy_to_cms_app;
  }

  # No basic auth security on the heartbeat url, so that ELB can use it
  location /heartbeat {
    try_files $uri @proxy_to_cms_app;
  }

      # static pages for server status
  location ~ ^/server/(?P<file>.*) {
      root /edx/var/nginx/server-static;
      try_files /$file =404;
  }

  location ~ ^/static/(?P<file>.*) {
    root /edx/var/edxapp;
    try_files /staticfiles/$file /course_static/$file =404;

    # return a 403 for static files that shouldn't be
    # in the staticfiles directory
    location ~ ^/static/(?:.*)(?:\.xml|\.json|README.TXT) {
        return 403;
    }

    # http://www.red-team-design.com/firefox-doesnt-allow-cross-domain-fonts-by-default
    location ~ "/static/(?P<collected>.*\.[0-9a-f]{12}\.(eot|otf|ttf|woff|woff2)$)" {
        expires max;
        add_header Access-Control-Allow-Origin *;
        try_files /staticfiles/$collected /course_static/$collected =404;
    }

    # Set django-pipelined files to maximum cache time
    location ~ "/static/(?P<collected>.*\.[0-9a-f]{12}\..*)" {
        expires max;
        # Without this try_files, files that have been run through
        # django-pipeline return 404s
        try_files /staticfiles/$collected /course_static/$collected =404;
    }

    # Set django-pipelined files for studio to maximum cache time
    location ~ "/static/(?P<collected>[0-9a-f]{7}/.*)" {
        expires max;

        # Without this try_files, files that have been run through
        # django-pipeline return 404s
        try_files /staticfiles/$collected /course_static/$collected =404;
    }

    # Expire other static files immediately (there should be very few / none of these)
    expires epoch;
  }


}
上游cms后端{
服务器127.0.0.1:8010失败\u超时=0;
}
服务器{
听18010;
服务器名称“”;
返回301 https://$server\u name:18010$request\u uri;
}
服务器{
#nginx的CMS配置文件,由ansible模板化
#远程维护页面的代理
#错误页
错误\u第504页/server/server-error.html;
错误\u第502页/server/server-error.html;
错误\u第500页/server/server-error.html;
听443ssl;
听[:]:443 ssl;
包括snippets/ssl-cabsacademie.conf;
包括snippets/ssl-params.conf;
#使用高隐私设置防止IE 10+中的无效显示课件
add_header P3P'CP=“开放式edX没有P3P策略。”;
#Nginx不支持嵌套条件或其他条件
#这里有各种不幸的情况。
服务器名称“”;
access_log/edx/var/log/nginx/access.log p_组合;
error\u log/edx/var/log/nginx/error.log error;
#CS184要求上传高达4MB的屏幕截图。
#CMS需要更大的课程资产价值,提供的价值
#经由希拉。
客户最大身体尺寸为100M;
重写^(.*)/favicon.ico$/static/images/favicon.ico last;
#Blackholes是python库文件的存档,讲师可以使用它
#可以提供沙盒python问题类型,内部
#指令将导致nginx发出nginx 404.Users
#将不会重定向到应用程序404页面。
位置~*python_lib.zip{
内部的;
}
#nginx配置中使用的通用设置
#禁用页面和标题中的服务器版本反馈
服务器_令牌关闭;
位置@proxy\u to\u cms\u应用程序{
代理集头X-Forwarded-Proto$方案;
代理\u设置\u头X转发端口$server\u端口;
$remote\u addr的代理\u集\u头X转发;
#newrelic特定的头记录nginx处理请求的时间。
代理集头X-Queue-Start“t=${msec}”;
代理设置头主机$http\U主机;
代理_重定向关闭;
代理通行证http://cms-backend;
}
地点/{
尝试将$uri@proxy\u文件添加到\u cms\u应用程序;
}
#github\u服务\u钩子url上没有基本的身份验证安全性,因此github可以将其用于cms
位置/github\u服务\u挂钩{
尝试将$uri@proxy\u文件添加到\u cms\u应用程序;
}
#心跳url上没有基本的身份验证安全性,因此ELB可以使用它
位置/心跳{
尝试将$uri@proxy\u文件添加到\u cms\u应用程序;
}
#服务器状态的静态页面
位置^/server/(?P.*){
root/edx/var/nginx/server static;
try_files/$file=404;
}
位置^/static/(?P.*){
root/edx/var/edxapp;
try_files/staticfiles/$file/course_static/$file=404;
#对于不应被删除的静态文件,返回403
#在staticfiles目录中
位置^/static/(?:.*)(?:\.xml |\.json | README.TXT){
返回403;
}
# http://www.red-team-design.com/firefox-doesnt-allow-cross-domain-fonts-by-default
位置~“/static/(?P.\[0-9a-f]{12}\(eot | otf | ttf | woff | woff2)$)”{
最大值;
添加_头访问控制允许原点*;
try_files/staticfiles/$collected/course_static/$collected=404;
}
#将django管道文件设置为最大缓存时间
位置~“/static/(?P.\[0-9a-f]{12}\..*)”{
最大值;
#如果不使用此try_文件,则为已运行的文件
#django管道返回404s
try_files/staticfiles/$collected/course_static/$collected=404;
}
#将studio的django管道文件设置为最大缓存时间
位置~“/static/(?P[0-9a-f]{7}/*)”{
最大值;
#如果不使用此try_文件,则为已运行的文件
#django管道返回404s
try_files/staticfiles/$collected/course_static/$collected=404;
}
#立即终止其他静态文件(这些文件应该很少/没有)
新纪元;
}
}

无论何时访问浏览器,都会出现此错误-

您有两个服务器块使用相同的服务器名称侦听端口18010。您还可以使用将扩展为空字符串的
$server\u name
。请参阅以获取指导。@RichardSmith不,我没有两个服务器块监听端口18010。只有一个。应用程序结构是这样的-应用程序1-端口80,服务器名称mydomain.com应用程序2-端口18010,现在这里mydomain.com是相同的,但我想听听18010这是你的问题,我可以清楚地看到两个
服务器
块,每个块都有
侦听18010语句和一个
服务器名称“”语句。@RichardSmith那是个打字错误。我更正了它,它仍然不工作。确定:-)另一个问题是
返回301 https://$server\u name:18010$request\u uri
将尝试重定向到自身,但方案错误且
$server\u name
无论如何都是空字符串。