centos 7上Nginx反向代理apache,同时配置http和https

Nginx reverse proxy apache on centos 7, configuring both http and https

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

我成功地为 http 配置了这两个,但是在为 Apache 安装了 lets encrypt 证书之后,我看到 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;
     } 
}

注意:我使用的是php7.0

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

What I was actually going to implement: I was trying to run both node.js and apache using nginx. I donot start node yet.

我的问题:

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

晚上好, 首先,您在基础架构级别所做的所有考虑都非常好,我认为尽管此时实施困难,但代理配置是最好的。

我已经使用它一段时间了,受益匪浅。但是,我想问一下您使用的是什么类型的云基础设施,因为根据技术基础设施的不同,会发生很多变化。例如,我只使用与 CloudFlare 或其他 AWS 完全不同的 Google Cloud Platform。

所做的配置从结构的角度来看过于清晰和不清楚。你应该试试这个 way:First,使用上游域名指令输入 http 上下文,使用 Apache 输入服务器 IP 地址,然后通过包含 proxy_params 文件的参数来声明服务器和位置上下文和片段 ssl.

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

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

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