本文将介绍Linux_Mail_Server的详细情况,。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于$_SERVER["HTTP_HOST"]和$_SER
本文将介绍Linux_Mail_Server的详细情况,。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于$_SERVER["HTTP_HOST"]和$_SERVER["SERVER_NAME"]、$_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']是什么错误?、$_SERVER[''PHP_SELF'']、$_SERVER[''SCRIPT_NAME''] 与 $_SERVER[''REQUEST_URI'']三者的区别、ember.js – 在EmberJS中使用Rails active_model_serializers在非标准类名中加载对象的知识。
本文目录一览:- Linux_Mail_Server
- $_SERVER["HTTP_HOST"]和$_SERVER["SERVER_NAME"]
- $_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']是什么错误?
- $_SERVER[''PHP_SELF'']、$_SERVER[''SCRIPT_NAME''] 与 $_SERVER[''REQUEST_URI'']三者的区别
- ember.js – 在EmberJS中使用Rails active_model_serializers在非标准类名中加载对象
Linux_Mail_Server
mail 服务器分为发邮件和收邮件,发邮件主要由 sendmail 来完成,收邮件主要由 dovecot 来完成,当然也有其它的软件,该文介绍 sendmail+dovecot=mail 服务器的架设。配置 mail 服务器所需软件
[root@ding ~]# rpm -qa | grep sendmail
sendmail-cf-8.13.8-8.1.el5_7
sendmail-8.13.8-8.1.el5_7
[root@ding ~]# rpm -qa | grep m4
m4-1.4.5-3.el5.1
配置主配置文件
[root@ding ~]# vi /etc/mail/sendmail.mc
52 TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN'')dnl 开启认证
53 define(`confAUTH_MECHANISMS'', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLA
IN'')dnl
116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA'')dnl 修改为全网段监听
写进真正的配置文件
[root@ding ~]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
配置短域名
[root@ding ~]# vi /etc/mail/local-host-names
1 # local-host-names - include all aliases for your machine here.
2 ding
3 mail.ding
启动 sendmail
[root@ding ~]# service sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@ding ~]# service saslauthd restart
Stopping saslauthd: [ OK ]
Starting saslauthd: [ OK ]
[root@ding ~]# netstat -ntl | grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
配置 dovecot
[root@ding ~]# rpm -qa | grep dovecot
dovecot-1.0.7-8.el5_9.1
[root@ding ~]# vi /etc/dovecot.conf
20 protocols = imap imaps pop3 pop3s
[root@ding ~]# service dovecot restart
Stopping Dovecot Imap: [ OK ]
Starting Dovecot Imap: [ OK ]
[root@ding ~]# netstat -ntl | grep 143
tcp 0 0 :::143 :::* LISTEN
配置 foxmail 客户端
Email Adress: dh@ding
passsword: ********
Receiver type: pop3
Account: dh
password: ********
IMAP server: mail.ding
SMTP server: mail.ding
mail.ding 邮箱自发自收成功
[root@ding ~]# mail -s "hello" dh@mail.ding
hi,
I am ding.
.
Cc:
tail -F /var/log/maillog
Jan 1 17:25:08 ding sendmail[11012]: t021P8LM011012: from=root, size=44, class=0, nrcpts=1, msgid=<201501020125.t021P8LM011012@ding.net>, relay=root@localhost
Jan 1 17:25:08 ding sendmail[11013]: t021P8cw011013: from=<root@ding.net>, size=295, class=0, nrcpts=1, msgid=<201501020125.t021P8LM011012@ding.net>, proto=ESMTP, daemon=MTA, relay=ding [127.0.0.1]
Jan 1 17:25:08 ding sendmail[11014]: t021P8cw011013: forward /home/dh/.forward.localhost: World writable directory
Jan 1 17:25:08 ding sendmail[11014]: t021P8cw011013: forward /home/dh/.forward: World writable directory
Jan 1 17:25:08 ding sendmail[11012]: t021P8LM011012: to=dh@mail.ding, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30044, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t021P8cw011013 Message accepted for delivery)
Jan 1 17:25:08 ding sendmail[11014]: t021P8cw011013: to=<dh@mail.ding>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30471, dsn=2.0.0, stat=Sent
ding sendmail server (192.168.0.114) 和 hding sendmail server (192.168.0.111) 互发邮件: XP (192.168.0.101) 用 foxmail 作为客户端:
分析:两台 server 分别有自己的 DNS server,分别有自己的 sendmail server,即它们是互相独立的,如何能让对方认出自己,给自己发邮件,需要 DNS 互相解析,其中这边应用的是 forward DNS
[root@hding ~]# vi /etc/named.conf
26 zone "ding" {
27 type forward;
28 forwarders {192.168.0.114;};
29 };
[root@ding ~]# vi /etc/named.conf
27 zone "hding" {
28 type forward;
29 forwarders {192.168.0.111;};
30 };
客户端也需要能解析这两边的地址,所以只需要指向他们其中的一个作为 DNS server 则能全部解析出来
mail over ssl[root@hding ~]# cd /etc/pki/tls/certs/
[root@hding certs]# make sendmail.pem
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
cat $PEM1 > sendmail.pem ; \
echo "" >> sendmail.pem ; \
cat $PEM2 >> sendmail.pem ; \
rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
................................+++
....................+++
writing new private key to ''/tmp/openssl.pw7007''
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ''.'', the field will be left blank.
-----
Country Name (2 letter code) [GB]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [Newbury]:
Organization Name (eg, company) [My Company Ltd]:
Organizational Unit Name (eg, section) []:qa
Common Name (eg, your name or your server''s hostname) []:hding
Email Address []:dh@mail.hding
[root@hding certs]# vi /etc/mail/sendmail.mc
134 DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s'')dnl
60 define(`confCACERT_PATH'', `/etc/pki/tls/certs'')dnl
61 define(`confCACERT'', `/etc/pki/tls/certs/ca-bundle.crt'')dnl
62 define(`confSERVER_CERT'', `/etc/pki/tls/certs/sendmail.pem'')dnl
63 define(`confSERVER_KEY'', `/etc/pki/tls/certs/sendmail.pem'')dnl
[root@hding certs]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
[root@hding certs]# service sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@hding certs]# vi /etc/dovecot.conf
85 ssl_disable = no
91 ssl_cert_file = /etc/pki/dovecot/certs/dovecot.pem
92 ssl_key_file = /etc/pki/dovecot/private/dovecot.pem
[root@hding certs]# service dovecot restart
Stopping Dovecot Imap: [ OK ]
Starting Dovecot Imap: [ OK ]
[root@hding certs]# netstat -ntlp
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 7063/sendmail: acce
tcp 0 0 :::995 :::* LISTEN 7097/dovecot
sendmail log:
Jan 9 16:06:09 hding sendmail[7151]: STARTTLS=server, relay=[192.168.0.101], version=TLSv1/SSLv3, verify=NO, cipher=DHE-RSA-AES256-SHA, bits=256/256
Jan 9 16:06:10 hding sendmail[7151]: AUTH=server, relay=[192.168.0.101], authid=dh@hding, mech=LOGIN, bits=0
Jan 9 16:06:10 hding sendmail[7151]: t0A0696o007151: from=<dh@hding>, size=1237, class=0, nrcpts=1, msgid=<2015011822462078142417@hding>, proto=ESMTP, daemon=TLSMTA, relay=[192.168.0.101]
Jan 9 16:06:23 hding sendmail[7153]: t0A0696o007151: to=<dh@mail.ding>, ctladdr=<dh@hding> (501/501), delay=00:00:13, xdelay=00:00:13, mailer=esmtp, pri=121237, relay=mail.ding. [192.168.0.114], dsn=2.0.0, stat=Sent (t0226na6011114 Message accepted for delivery)
dovecot log:
Jan 9 16:09:43 hding sendmail[7160]: STARTTLS=server, relay=[192.168.0.114], version=TLSv1/SSLv3, verify=NO, cipher=DHE-RSA-AES256-SHA, bits=256/256
Jan 9 16:09:43 hding sendmail[7160]: t0A09hjW007160: from=<dh@ding.net>, size=1395, class=0, nrcpts=1, msgid=<2015011822495417159318@ding>, proto=ESMTP, daemon=MTA, relay=[192.168.0.114]
Jan 9 16:09:43 hding sendmail[7161]: t0A09hjW007160: forward /home/dh/.forward.hding: World writable directory
Jan 9 16:09:43 hding sendmail[7161]: t0A09hjW007160: forward /home/dh/.forward: World writable directory
Jan 9 16:09:43 hding sendmail[7161]: t0A09hjW007160: to=<dh@mail.hding>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31634, dsn=2.0.0, stat=Sent
Jan 9 16:10:03 hding dovecot: pop3-login: Aborted login: user=<dh@hding>, method=PLAIN, rip=::ffff:192.168.0.101, lip=::ffff:192.168.0.111, TLS
Jan 9 16:10:03 hding dovecot: pop3-login: Login: user=<dh>, method=PLAIN, rip=::ffff:192.168.0.101, lip=::ffff:192.168.0.111, TLS
Jan 9 16:10:03 hding dovecot: POP3(dh): Disconnected: Logged out top=0/0, retr=1/1717, del=0/15, size=31636
这次 server 的搭建过程中遇到的问题,总结如下:
1 foxmail中不让用mail.ding作为域名解析, 原因不是因为寻找不到主机,而是因为我把client相应的DNS设置成备用的,设置成主用即可
2 foxmail中设置pop3与imap的方式不同,pop3设置账号需要邮件全名dh@xxx, IMAP却不能写全名,只能写dh而无需@xxx
3 Dec 31 19:53:45 ding sendmail[7647]: t013rjmj007645: to=<dh@mail.hding>, ctladdr=<dh@ding> (501/501), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121182, relay=mail.hding. [192.168.0.111], dsn=5.6.0, stat=Data format error
hosts中127.0.0.1中的主机名要排在第一个,比localhost前
[root@ding mail]# vi /etc/hosts
1 # Do not remove the following line, or various programs
2 # that require network functionality will fail.
3 127.0.0.1 ding ding.net
4 ::1 localhost6.localdomain6 localhost6
4 Jan 8 16:53:37 localhost sendmail[6444]: t090rb5Q006442: SYSERR(root): ding.localdomain. config error: mail loops back to me (MX problem?)
Jan 8 16:53:37 localhost sendmail[6444]: t090rb5Q006442: to=<dh@ding.localdomain>, ctladdr=<root@localhost.localdomain> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120325, relay=ding.localdomain. [192.168.0.114], dsn=5.3.5, stat=Local configuration error
日志看出是localdomain发出来的,显然主机名不对,设置完主机名后需要重启
vi /etc/hosts
vi /etc/sysconfig/network
hostname
5 Jan 8 17:08:03 localhost sendmail[6491]: t09180FI006491: to=dh@ding, ctladdr=root (0/0), delay=00:00:03, xdelay=00:00:03, mailer=relay, pri=30031, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t09180Fo006492 Message accepted for delivery)
Jan 8 17:08:25 localhost sendmail[6494]: t09180Fo006492: to=<dh@ding.com>, ctladdr=<root@hding.com> (0/0), delay=00:00:22, xdelay=00:00:22, mailer=esmtp, pri=120284, relay=ding-com.mail.protection.outlook.com. [213.199.154.23], dsn=5.7.1, stat=User unknown
不能发@ding, 必需是mail.ding
6 Jan 8 16:46:02 localhost sendmail[6394]: t090k2uo006392: to=<dh@ding>, ctladdr=<root@localhost.localdomain> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120313, relay=ding, dsn=5.1.2, stat=Host unknown (Name server: ding: host not found)
本地DNS不能解析对方的server,所以在发之前先用nslookup看看
7 Jan 8 10:55:04 localhost sendmail[5549]: t08It4xn005549: ding.terry.com [192.168.0.114] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
MTA已经是ding,主机名却是ding.terry.com
目前两台 server 总算工作正常,中间也在网上找了很多资料,好不容易搞能了,希望能帮助其它人早日找到解决问题的办法
$_SERVER["HTTP_HOST"]和$_SERVER["SERVER_NAME"]
开发站群软件,用到了根据访问域名判断子站点的相关问题,PHP获取当前域名有两个变量 $_SERVER[''HTTP_HOST''] 和 $_SERVER[''SERVER_NAME''],两者的区别以及哪个更加可靠?
相同点:
当满足以下三个条件时,两者会输出相同信息。
1、服务器为80端口
2、apache的conf中ServerName设置正确
3、HTTP/1.1协议规范
不同点:
1、通常情况:
$_SERVER["HTTP_HOST"] 在HTTP/1.1协议规范下,会根据客户端的HTTP请求输出信息。
$_SERVER["SERVER_NAME"] 默认情况下直接输出apache的配置文件httpd.conf中的ServerName值。
2、当服务器为非80端口时:
$_SERVER["HTTP_HOST"] 会输出端口号,例如:snsgou.com:8080
$_SERVER["SERVER_NAME"] 会直接输出ServerName值
因此在这种情况下,可以理解为:$_SERVER[''HTTP_HOST''] = $_SERVER[''SERVER_NAME''] : $_SERVER[''SERVER_PORT'']
3、当配置文件httpd.conf中的ServerName与HTTP/1.0请求的域名不一致时:
httpd.conf配置如下:
<virtualhost *>
ServerName snsgou.com
ServerAlias blog.snsgou.com
</virtualhost>
客户端访问域名 blog.snsgou.com
$_SERVER["HTTP_HOST"] 输出 blog.snsgou.com
$_SERVER["SERVER_NAME"] 输出 snsgou.com
所以,在实际程序中,应尽量使用_SERVER["HTTP_HOST"] ,比较保险和可靠。
$_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']是什么错误?
$_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']是什么东东??
在某一网站程序的php文件中看到这段代码:$md5str = ((((''EHTAZIYT''.$ep).$_SERVER[''SERVER_ADDR'']).$_SERVER[''LOCAL_ADDR'']).''22.90h7^aaz0(!skZnmLa03#nVAc_f(h-a!)wsx~9dlP1%uXJnB8.65E3zYYwa'');可我运行到些段代码时老是会停下来,弹出如下错误信息Notice: Undefined index。指示$_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']为无效变量。请问:$_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']到底是什么东西,我查php手册也没查出,可这段代码却出现在商业程序中,已经过数年的运行检验,不应该是错误的。
请知道的兄弟姐妹们能解答下。
------解决方案--------------------
“SERVER_ADDR”
当前运行脚本所在的服务器的 IP 地址。
“REMOTE_ADDR”
正在浏览当前页面用户的 IP 地址。
LOCAL_ADDR不晓得是啥,估计是自己加进去的
------解决方案--------------------
$_SERVER[''LOCAL_ADDR''] 在PHP5中已经没有了
$_SERVER[''PHP_SELF'']、$_SERVER[''SCRIPT_NAME''] 与 $_SERVER[''REQUEST_URI'']三者的区别
$_SERVER[''PHP_SELF'']、$_SERVER[''SCRIPT_NAME''] 与 $_SERVER[''REQUEST_URI''] 三者非常相似,返回的都是与当前 URL 或 PHP 程序文件相关的信息:
1.$_SERVER[''PHP_SELF'']:相对于网站根目录的路径及 PHP 程序名称。
2.$_SERVER[''SCRIPT_NAME'']:相对于网站根目录的路径及 PHP 程序文件名称。
3.$_SERVER[''REQUEST_URI'']:访问此页面所需的 URI 。
一个简单的例子可以看出它们的区别。URL 地址如下:
http://www.5idev.com/php/index.php/test/foo?username=hbolive
$_SERVER[''PHP_SELF''] 得到:/php/index.php/test/foo
$_SERVER[''SCRIPT_NAME''] 得到:/php/index.php
$_SERVER[''REQUEST_URI''] 得到:/php/index.php/test/foo?username=hbolive
从该例子可以看出:
1.$_SERVER[''PHP_SELF''] 则反映的是 PHP 程序本身;
2.$_SERVER[''SCRIPT_NAME''] 反映的是程序文件本身(这在页面需要指向自己时非常有用);
3.$_SERVER[''REQUEST_URI''] 则反映了完整 URL 地址(不包括主机名)。
其实从各自的命名上,也可以体现出它们之间的细微差别。 特别的,对于如下地址:
http://www.5idev.com/
$_SERVER[''PHP_SELF''] 得到:/index.php $_SERVER[''SCRIPT_NAME''] 得到:/index.php $_SERVER[''REQUEST_URI''] 得到:/
至于有人提到 $_SERVER[''PHP_SELF''] 与 $_SERVER[''SCRIPT_NAME''] 在 PHP 以 CGI 模式运行下会有区别。由于 PHP 在 CGI 模式运行下并不多见,测试较为麻烦,在此就不再叙述了。如有这种情况,可注意并自行测试。
希望在理解了它们之间的区别之后,以便选择更适合自己程序的来使用。
ember.js – 在EmberJS中使用Rails active_model_serializers在非标准类名中加载对象
class Issue < ActiveRecord::Base belongs_to :reporter,class_name: 'User' belongs_to :assignee,class_name: 'User' has_many :comments end class User < ActiveRecord::Base end class Comment < ActiveRecord::Base end
像这样的序列化器:
class IssueSerializer < ActiveModel::Serializer attributes :id embed :ids,include: true has_one :reporter,:embed => :ids has_one :assignee,:embed => :ids end class UserSerializer < ActiveModel::Serializer attributes :id,:name end class CommentSerializer < ActiveModel::Serializer attributes :id,:body end
这会生成类似于以下内容的JSON:
{ "issues": [ { "id": 6,"reporter_id": 1,"assignee_id": 2,"comment_ids": [ 3 ] },],"comments": [ { "id": 3 "body": "Great comment" } ],"reporters": [ { "id": 1 "name": "Ben Burton" } ],"assignees": [ { "id": 2 "name": "Jono Mallanyk" } ] }
问题是侧载报告人和受让人JSON对象不被Ember识别为User对象,我看到以下错误:
Uncaught Error: assertion Failed: Your server returned a hash with the key reporters but you have no mapping for it
我不想删除
embed :ids,include: true
来自我的IssueSerializer,因为那时评论不会被序列化.
我考虑过有几种可能解决这个问题的方法:
>如果ActiveModel :: Serializer的embed方法在其include选项中接受了模型列表,则可以将JSON响应过滤为仅包含侧载注释.
> Ember数据的模型可以配置为从“用户”,“记者”和“受让人”侧面加载用户……但据我所知,从源代码来看,它似乎只支持sideloadAs的一个密钥.
>以某种方式忽略/禁用未知密钥的侧载错误(可能是最不理智的方法).
我还缺少另一种选择吗?我想我可能必须写一个修复程序并向pull-api / active_model_serializers,emberjs / data或两者提交pull请求.
编辑:我的临时解决方法是将IssueSerializer更改为仅序列化记者和受让人的ID:
class IssueSerializer < ActiveModel::Serializer attributes :id,:reporter_id,:assignee_id embed :ids,include: true has_many :comments,:embed => :ids end
解决方法
class IssueSerializer < ActiveModel::Serializer attributes :id embed :ids,:root => "users" has_one :assignee,:root => "users" has_many :comments end
关于Linux_Mail_Server的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于$_SERVER["HTTP_HOST"]和$_SERVER["SERVER_NAME"]、$_SERVER[''LOCAL_ADDR'']和$_SERVER[''SERVER_ADDR'']是什么错误?、$_SERVER[''PHP_SELF'']、$_SERVER[''SCRIPT_NAME''] 与 $_SERVER[''REQUEST_URI'']三者的区别、ember.js – 在EmberJS中使用Rails active_model_serializers在非标准类名中加载对象的相关知识,请在本站寻找。
本文标签: