在 Alpine 上托管 Web/电子邮件服务
![]() 它应该与 Hosting services on Alpine 合并。 (讨论) |
简介
此信息来自 Alpine Wiki 网站上的其他几个页面(见链接)以及特定软件包的网站。这是一个建议/分步说明指南。
您可能想知道,为什么有人想在 RAM 中运行的 Linux 安装上运行 Web 和电子邮件服务? 问得好。 使用 Vservers,我们可以在内存中运行主机,并使用访客执行各种操作。 将访客放在主机中的 DAS 上,或为访客执行 RAID iSCSI。 这样,如果您的磁盘开始出现故障或完全掉线,您很可能能够从正在运行的系统中访问数据。
Guest OS here or [Host Alpine Box] --------------------- [DAS] | | | |Guest OS here | | iSCSI iSCSI
Web 服务
有很多 http 服务器。 Alpine 自带了几种不同的服务器。 在本指南中,我们安装了 lighttpd。
apk_fetch -u apk_get install lighttpd openssl php
lighttpd 已经处理了大部分事情。 确保取消注释 ssl 选项
ssl.engine = "enable" ssl.pemfile = "/etc/lighttpd/server.pem"
rc-service lighttpd start
请看下面关于生成 server.pem 的内容
现在您可以开始使用 lighttpd 并开始制作您自己的网站。 如果您想使用 phpBB 和 mediawiki,Alpine 自带了它们。 您可能需要使用 sql 数据库。 放置页面的位置是
/var/www/localhost/htdocs/
默认情况下,lighttpd 正确使用符号链接。 因此,当您的页面也可能位于其他位置时,您可以只符号链接到目录
ln -s /home/user/htdocs /var/www/localhost/htdocs/user
生成 Server.pem
对于其他服务,我们也将使用 ssl。 一种简单的入门方法是生成您自己的自签名证书。 脚本和配置文件取自 Alpine 上的 setup-webconf 脚本。
ssl.cnf
[ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_dn x509_extensions = cert_type prompt = no [ req_dn ] OU=HTTPS server CN=example.net emailAddress=postmaster@example.net [ cert_type ] nsCertType = server
ssl.sh
#/bin/sh openssl genrsa 512/1024 >server.pem openssl req -new -key server.pem -days 365 -out request.pem openssl genrsa 2048 > keyfile.pem openssl req -new -x509 -nodes -sha1 -days 3650 -key keyfile.pem \ -config ssl.cnf > server.pem cat keyfile.pem >> server.pem
如果您使用此方法为其他服务生成 ssl 证书,您可以只更改 req_dn 信息。
邮件服务
此处也可以找到一些呈现的信息。 然而,这是为电子邮件网关准备的。使用 Alpine 保护您的电子邮件服务器
apk_get install postfix dovecot clamav clamsmtpd gross
Postfix
Postfix 有一些东西需要添加到其配置中,以便它可以通过 clamav 发送电子邮件,并且它将接受域和用户的邮件。
Main.cf
vi /etc/postfix/main.cf
#/etc/postfix/main.cf myhostname = mx.example.net mydomain = example.net relayhost = #blank will do dns lookups for destinations home_maildir = Maildir/ smtpd_banner = $myhostname ESMTP #The way postfix answers. transport_maps = hash:/etc/postfix/transport #Place to add how you want to route domains. See example below. Show how to host more than one domain. local_transport = virtual virtual_mailbox_domains = example.net, bobo.net #list of hosted domains virtual_mailbox_base = /var/spool/vhosts virtual_uid_maps = static:1004 # uid of user to be used to read/write mail virtual_gid_maps = static:1004 # gid of user to be used to read/write mail virtual_alias_maps = hash:/etc/postfix/valias #alias for each different hosted domain. See below. virtual_mailbox_maps = hash:/etc/postfix/vmap #where and what mailbox to drop the mail to. See below. smtpd_helo_required = yes disable_vrfy_command = yes content_filter = scan:[127.0.0.1]:10025 # clamscan to be configured later smtpd_recipient_restrictions = reject_unauth_pipelining, permit_sasl_authenticated,permit_mynetworks,reject_invalid_hostname, reject_non_fqdn_hostname,reject_non_fqdn_sender, reject_non_fqdn_recipient,reject_unknown_sender_domain, reject_unknown_recipient_domain,reject_unauth_destination, check_policy_service inet:127.0.0.1:5525,permit smtpd_data_restrictions = reject_unauth_pipelining, permit smtpd_sasl_auth_enable = yes broken_sasl_auth_clients = yes smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_tls_cert_file = /etc/ssl/postfix/server.pem smtpd_tls_key_file = $smtpd_tls_cert_file
Master.cf
master.cf 中用于病毒/垃圾邮件扫描的设置。 将这些添加到文件末尾。 类似于 使用 Alpine 保护您的电子邮件服务器 中找到的那些。
scan unix - - n - 16 smtp -o smtp_send_xforward_command=yes -o smtp_enforce_tsl=no 127.0.0.1:10026 inet n - n - 16 smtpd -o content_filter= -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks -o smtpd_helo_restrictions= -o smtpd_client_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks_style=host -o smtpd_authorized_xforward_host=127.0.0.1/8
Valias
#etc/postfix/valias postmaster@example.net user1@example.net hostmaster@example.net user2@example.net hostmaster@bobo.net user1@example.net postmaster@bobo.net user2@bobo.net
Vmap
#/etc/postfix/vmap user1@example.net example.net/user1 user2@example.net example.net/user2 @example.net example.net/catchall #everyone else doesn't match rule above
Transport
#/etc/postfix/transport example.net virtual: bobo.net virtual: foo.net smtp:1.2.3.4 #send foo.net through this smtp server * : #everything else go through relayhost rule
一旦创建了这些文件,您需要将它们制成 .db 文件
postmap valias postmap transport postmap vmap
Dovecot
目前,Alpine 上的 Dovecot 只提供 imap 和 imaps 服务。
Dovecot 的大部分已经为 imap 配置好了。 您可能需要像上面显示的那样生成密钥。 只需稍微更改 cnf 文件,使其说明关于 mail.domainname 的内容即可。
ssl_cert_file = /etc/ssl/dovecot/server.pem ssl_key_file = /etc/ssl/dovecot/keyfile.pem mail_location = maildir:/var/spool/vhosts/&d/%n valid_chroot_dirs = /var/spool/vhosts passdb passwd-file { args = /etc/dovecot/passwd } userdb passwd-file { args = /etc/dovecot/users } #section for postfix sasl auth socket listen { client { path = /var/spool/postfix/private/auth user = postfix group = postfix mode = 0660 } }
要生成密码,您可以使用 dovecotpw 命令。
dovecotpw -s MD5-CRYPT
下面的哈希可以用于密码 test123
/etc/dovecot/passwd 文件应该像这样
user1@example.net:$1$tz5sbjAD$Wq9.NkSyNo/oElzFgI68.0 user2@example.net:$1$tz5sbjAD$Wq9.NkSyNo/oElzFgI68.0
THe /etc/dovecot/userdb 文件应该像这样
user1@example.net::1004:1004::/var/spool/vhosts/example.net/:/bin/false:: user2@example.net::1004:1004::/var/spool/vhosts/example.net/:/bin/false:: user@domain::uid : gid of found in virtual_uid_maps::location of maildir:shell::
Clamsmtpd
根据说明配置 使用 Alpine 保护您的电子邮件服务器
Gross
根据说明配置 使用 Alpine 保护您的电子邮件服务器
最后步骤
启动服务并确保使用 rc_add 添加它们
rc-service postfix start rc_add -k postfix