【问题标题】:Securing Nginx with SSL使用 SSL 保护 Nginx
【发布时间】:2017-12-30 08:55:58
【问题描述】:

我正在使用 SSL 保护 Nginx 服务器,我有一个问题。我有两台虚拟服务器,一台用于 http 监听端口 80,https 监听 443,如下所示:

 # HTTP server
server {
        listen       80;
        server_name  localhost; 
        ...
        # many configuration rules here for caching, etc
}
# HTTPS server
    server {
        listen       443 ssl;
        server_name  localhost;
        ...
}

问题是,我是否需要将我在 http 版本中的所有配置规则复制到我的 https 版本中?有什么办法可以避免重复所有这些规则?

更新 我正在尝试根据@ibueker 的回答配置一个包含。看起来很容易,但不知何故不起作用。包含是否需要在某个位置内?附上示例:

 # HTTP server
    server {
            listen       80;
            server_name  localhost; 
            ...
            include ./wpo
    }

wpo 文件在同一路径中,就像:

# Expire rules for static content
# RCM: WPO
# Images                                                   
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
        root    /home/ubuntu/env/production/www/yanpy/app;
        expires 1w;
        add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
        root  /home/ubuntu/env/production/www/yanpy/app;
        expires 1w;
        add_header Cache-Control "public";
}

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
        root   /home/ubuntu/env/production/www/yanpy/app;
        expires -1;
}

【问题讨论】:

    标签: ssl nginx


    【解决方案1】:

    您可以将它们放在另一个文件中,并将它们包含在两个服务器块中。

    include /path/to/file;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 2022-01-16
      • 2011-09-19
      • 2011-03-10
      相关资源
      最近更新 更多