ssl - 使用 SSL 保护 Nginx

标签 ssl nginx

我使用 SSL 保护 Nginx 服务器,我有一个问题。我有两个虚拟服务器,一个用于在端口 80 中监听 http,另一个在 443 中监听 https:

 # 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;
}

最佳答案

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

include /path/to/file;

关于ssl - 使用 SSL 保护 Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48032396/

相关文章:

wordpress - 实现 SSL(Digital Ocean + Nginx + Cloudflare)

google-chrome - Chrome ERR_CERT_AUTHORITY_INVALID

r - 添加 SSL 和 apache 后, Shiny 的服务器断开应用程序?

android - 在 android 应用程序中打包文件(但不在 res 或 assets 中)

ssl - Jetty SSL 配置 Apache karaf

ruby-on-rails - (使用 phusion passenger + Nginx)运行具有相同端口(80)的多个实例名称的相同 Rails 应用程序

php - 运行 PHP 时 Nginx 403 Forbidden

php - 如何为 php5-fpm/NGINX 启用 PHP IMAP?

php - 在 AWS Linux 上升级 PHP

nginx - 在 kubernetes pod 中重新加载 nginxconf