我的目标是从新的Ubuntu 16.04服务器提供安全的电子邮件服务。为了做到这一点,我想以nginx作为其反向代理来设置Apache2。
我的直接问题是Apache无法启动,声称没有分配SSL证书(请参阅本问题末尾的Terminal的输出),即使我(尚未)尝试使用HTTPS。
我的问题:
这是我对需要做的事情的理解。如果您能指出我的理解是错误的,我将不胜感激。
我想一次处理一个问题,所以我现在不理会SSL证书的问题,并试图让Apache仅在端口80上以nginx作为其反向代理运行。
这是我已有的配置文件:
Nginx的
$ sudo nano /etc/nginx/sites-available/webmail
server {
listen 80;
root /var/www/webmail/web;
index index.php index.html index.htm;
server_name webmail.mydomain.com;
# Look for...
# * the exact path
# * a default (index.*) file, considering the path to be a directory
# ... and if that fails:
# * get the index.php script at the root to deal with the request
location / {
try_files $uri $uri/ /index.php;
}
# If the chosen path leads to a PHP fie:
# * forward the request to Apache running at 127.0.0.1:8080
# * after having modified certain headers
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
# If there are any Apache HT files in the chosen directory
# ignore any direct requests for them
location ~ /\.ht {
deny all;
}
}
阿帕奇2
$ sudo nano /etc/apache2/sites-available/webmail.conf
<VirtualHost 127.0.0.1:8080>
ServerName webmail.mydomain.com
ServerAdmin [email protected]
DocumentRoot /var/www/webmail/web
<Directory "/var/www/webmail/web">
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Apache2端口
$ sudo nano /etc/apache2/ports.conf
Listen 127.0.0.1:8080
#<IfModule ssl_module>
# Listen 443
#</IfModule>
#<IfModule mod_gnutls.c>
# Listen 443
#</IfModule>
请注意,我明确不是要Apache监听端口443。在其他配置文件中是否还有其他地方告诉Apache监听端口443?
这是我的占位符PHP和HTML文件,位于它们的预期位置:
index.php
$ sudo nano /var/www/webmail/web/index.php
<?php
echo "PHP from /var/www/webmail/web/index.php\n";
?>
index.html
$ sudo nano /var/www/webmail/web/index.html
<html>
HTML from /var/www/webmail/web/index.html
</html>
在浏览器中,对http://webmail.mydomain.com/index.html的请求成功完成,但是对http://webmail.mydomain.com/index.php的请求导致文件被下载,而不执行。
当我尝试启动Apache2时,会发生以下情况:
$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.
$ sudo service apache2 status
* apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
`-apache2-systemd.conf
Active: inactive (dead) since <Time>; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 16059 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
Process: 16043 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
systemd[1]: Starting LSB: Apache2 web server...
apache2[16043]: * Starting Apache httpd web server apache2
apache2[16043]: Action 'start' failed.
apache2[16043]: The Apache error log may have more information.
apache2[16043]: *
apache2[16059]: * Stopping Apache httpd web server apache2
apache2[16059]: *
systemd[1]: Started LSB: Apache2 web server.
这是error.log的内容:
$ sudo nano /var/log/apache2/error.log
[ssl:emerg] [pid 15943] AH02572: Failed to configure at least one certificate and key for myhostname.hostingservice.com:443
[ssl:emerg] [pid 15943] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
[ssl:emerg] [pid 15943] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/error.log for more information
(这在var / log / apache2 / error.log中,没有更多信息。)
我一直想念什么?
注意:此服务器的主要目的是交付Meteor应用程序。我选择使用Phusion Passenger和Nginx进行此操作。除了电子邮件服务外,还将使用Apache交付WordPress网站。
我已经开始工作了。我忽略了删除/etc/apache2/sites-disabled/default-ssl.conf
,因此Apache试图运行不需要的安全站点。
随后sudo certbot --nginx
,我曾经获得Nginx的证书,现在一切都可以安全地进行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句