【问题标题】:Nginx reverse proxy apache on centos 7, configuring both http and httpscentos 7上的Nginx反向代理apache,同时配置http和https
【发布时间】:2017-07-26 01:06:11
【问题描述】:

我正在使用 Centos 7 将端口 80 的 nginx 配置为端口 8080 上的 Apache 服务器的代理服务器。

我成功地为 http 配置了两者,但是在安装了让 Apache 加密证书后,我看到 Apache 直接接收 https 的流量。我试图让 nginx 接收所有 HTTP 和 HTTPS 的流量,但遇到问题,

我做了很多改变,比如禁用 apache 监听 443 端口,只监听 8080。 我将 nginx 配置为在 80 和 443 监听,另外我删除了 apache 的证书并添加到 nginx 配置文件中。目前。

nginx配置如下:

server {
     listen       80;
     listen       [::]:80 default_server;
    #server_name  _;
     server_name www.example.com;

     root         /usr/share/nginx/html;

     # Load configuration files for the default server block.
     include /etc/nginx/default.d/*.conf;

    location / {

         proxy_pass http://my.server.ip.add:8080;
         root   /usr/share/nginx/html;
         proxy_redirect off;
         proxy_set_header X-Forwarded-Host $host;
         proxy_set_header X-Forwarded-Server $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
    }
    error_page 404 /404.html;
         location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
         location = /50x.html {
    }
}

server {
     listen 443 default_server;
     server_name www.example.com;

     root   /usr/share/nginx/html;

     ssl                  on;
     ssl_certificate      /etc/letsencrypt/live/www.example.com/cert.pem;
     ssl_certificate_key  /etc/letsencrypt/live/www.example.com/privkey.pem;

     ssl_prefer_server_ciphers on;
     ssl_session_timeout 1d;
     ssl_session_cache shared:SSL:50m;
     ssl_session_tickets off;

     # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
     #ssl_dhparam /etc/pki/nginx/dh2048.pem;

     # intermediate configuration. tweak to your needs.
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
     ssl_ciphers 'ECDHE-RSA--REMOVED-SOME-HERE-SHA';

     location / {
         proxy_pass http://127.0.0.1:8080;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto https;
     } 
}

注意:我使用的是 php 7.0

当前站点正在使用 https 和 http,但存在 1 个已知问题,即未加载用户图像。但我不确定它是由 apache 还是 nginx 提供的,在 RESPONSE 中我可以看到“nginx/1.10.2”

我实际上要实现的是:我试图同时运行 node.js 和 apache 使用 nginx。我还没有启动节点。

我的问题:

  1. 前端使用nginx,后端使用apache真的有好处吗? (我读过它可以防止 dDos 攻击)。
  2. 我们应该将证书放在 nginx 或 apache 的什么位置?
  3. 如何在 nginx 配置中添加 node.js?我已经安装了 node js。
  4. 同时使用 nginx 和 apache 的最佳配置是什么?

【问题讨论】:

    标签: apache ssl nginx reverse-proxy lets-encrypt


    【解决方案1】:

    晚上好, 首先,您在基础设施级别所做的所有考虑都非常好,在我看来,尽管目前实施困难,代理配置是最好的。

    我已经使用了一段时间了,它的好处是巨大的。但是,我想问一下您正在使用哪种类型的云基础架构,因为有很多事情会根据技术基础架构而改变。例如,我只使用与 CloudFlare 或其他 AWS 完全不同的 Google Cloud Platform。

    从结构的角度来看,所做的配置过于清晰和不清楚。您应该尝试这种方式:首先,使用上游域名指令输入 http 上下文,并使用 Apache 在服务器 IP 地址内部,然后通过包含 proxy_params 文件和 sn -p ssl 的参数来声明服务器和位置上下文。

    如果您想帮助我了解我们采用的基础架构,我们可以了解如何一起进行配置,但这是迫在眉睫的,因为每个基础架构都响应不同的配置。

    同样适用于php7.0。例如,使用 php7.0 配置 PrestaShop 1.7.1.1 我不得不对 CMS 的 php.ini 代码进行大量更改,因为我没有在 FPM 中使用 CGI,但正如我所说的那样变化很大。

    https://www.webfoobar.com/node/35

    【讨论】:

    • 尝试格式化您的答案,使其更清晰易懂
    • 对不起,我今天重温了SO,我用的是LINODE cloud VPS Server。
    猜你喜欢
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 2018-01-05
    • 2020-09-07
    • 1970-01-01
    • 2015-07-09
    • 2023-04-03
    • 2020-11-24
    相关资源
    最近更新 更多