nginx作为反向ssl代理(Apache + Varnish)跳过自己的configuration

我有一个新的Ubuntu 14.04安装与采取以下步骤:

  • Apache2 2.4.7
  • MariaDB上一个稳定的版本
  • PHP 7.0.9(和几个模块)
  • Apacheconfiguration为使用PHP7-FPM *
  • 使用Apache2的mod_rpaf **
  • PHPMyAdmin 4.6.3与PHP7.0.9正常工作。
  • WordPress 4.6 ***
  • 清漆4.0
  • Nginx 1.10.1在/etc/nginx/ssl中带有ssl证书

  • 和** – >问题发生在这些configuration之前和之后*** – > wp-config.php有强制ssllogin和ssl admin的代码。 两个工作都很好,只有Apache / Varnish。 为Apache创build了一个SSL证书,如果Apache设置为侦听端口443,则一切正常。

这是我的/etc/apache2/ports.conf:

#NameVirtualHost 192.168.1.86 ServerName 192.168.1.86 Listen 8080 #<IfModule ssl_module> # Listen 443 #</IfModule> #<IfModule mod_gnutls.c> # Listen 443 #</IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

这是我的/etc/apache2/sites-available/000-default.conf:

 <IfModule mod_fastcgi.c> AddHandler php7-fcgi-www-data .php Action php7-fcgi-www-data /php7-fcgi-www-data Alias /php7-fcgi-www-data /usr/lib/cgi-bin/php7-fcgi-www-data FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-www-data -socket /run/php/php7.0-fpm.www-data.sock -pass-header Authorization <Directory "/usr/lib/cgi-bin"> Require all granted </Directory> <FilesMatch ".+\.ph(p[345]?|t|tml)$"> SetHandler php7-fcgi-www-data </FilesMatch> </IfModule> <VirtualHost *:8080> ServerAdmin [email protected] DocumentRoot /var/www/html ServerName 192.168.1.86 <Directory /var/www/html/> AllowOverride All </Directory> Alias /phpmyadmin "/usr/share/phpmyadmin/" <Directory "/usr/share/phpmyadmin/"> Order allow,deny Allow from all Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

这是我的/etc/varnish/default.vcl中的'后端'部分:

 backend default { .host = "192.168.1.86"; .port = "8080"; } 

这是在我的/ etc / default / varnish中:

 DAEMON_OPTS="-a :80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,256m" 

这是我的/ etc / nginx / sites-available / default:

 server { listen 443 ssl; server_name 192.168.1.86; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; location / { proxy_pass http://192.168.1.86:80; 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; proxy_set_header X-Forwarded-Port 443; proxy_set_header Host $host; } } 
  • /etc/nginx/nginx.conf中的端口80没有任何痕迹。
  • /etc/apache2/sites-available/000-default.conf与启用网站的网站相匹配
  • / etc / nginx / sites-available / default匹配启用了站点的站点
  • 在/ etc / nginx / sites-available / default中使用“listen 443”尝试了很多组合,例如:

    listen 443 ssl default_server; listen [::]:443 ssl default_server ipv6only = on;

问题

https://192.168.1.86/wp-admin (或https://192.168.1.86等)显示“无法连接”,无论我在nginx conf文件中做什么。 尝试了很多东西。

Nginx似乎是好的(语法,configuration),但是,激活时,不起作用。 错误日志说:

 2016/08/23 14:02:07 [emerg] 10857#10857: bind() to 0.0.0.0:80 failed (98: Address already in use) 2016/08/23 14:02:07 [emerg] 10857#10857: bind() to 0.0.0.0:80 failed (98: Address already in use) 2016/08/23 14:02:07 [emerg] 10857#10857: bind() to 0.0.0.0:80 failed (98: Address already in use) 2016/08/23 14:02:07 [emerg] 10857#10857: bind() to 0.0.0.0:80 failed (98: Address already in use) 2016/08/23 14:02:07 [emerg] 10857#10857: bind() to 0.0.0.0:80 failed (98: Address already in use) 2016/08/23 14:02:07 [emerg] 10857#10857: still could not bind() 

由于某种原因,nginx正在尝试使用端口80,但它应该使用443。

我见过其他人有同样的问题,例如: nginx尝试绑定在错误的端口上

只是要清楚:我知道有一个服务器使用端口80.我不知道是为什么Nginx正在尝试使用端口80,当它应该使用443。

任何人都可以帮忙吗? 提前致谢

你可以尝试一些事情,而不是搞乱default文件configuration

a)在/etc/nginx/sites-available创build自己的configuration文件,然后启用/etc/nginx/sites-enabled的软链接

b)通过删除/etc/nginx/sites-enableddefault链接完全禁用default站点,或者简单地更改defaultconfiguration的端口,以便nginx在端口81中侦听(例如)

所以如果Nginx坚持在http中监听,或者任何导致这种行为的东西,它将不会使用端口80,并允许Varnish接受它。

或者升级到Ubuntu 16.04 LTS,这会给你一个包括Openssl v1.0.2 +在内的最新的东西,所以你可以启用HTTP / 2的支持。