ngxin做邮件代理
程序员文章站
2024-02-20 20:20:53
...
文章目录
关闭selinux,重启机器
[[email protected] tools]# cat /etc/selinux/config
.........
SELINUX=disabled
.........
[[email protected] tools]# init 6
下载必备的环境依赖
[[email protected] tools]#yum install gcc make pcre-devel zlib zlib-devel openssl openssl-devel pcre pcre-devel net-tools telnet -y
解压编辑,执行写好的shell脚本
[[email protected] tools]# tar -xvf nginx-1.18.0.tar.gz
[[email protected] tools]# ls
nginx-1.18.0 nginx-1.18.0.tar.gz nginx_proxy.sh
[[email protected] tools]# bash nginx_proxy.sh
#!/bin/bash
tar -xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx --with-mail --with-stream
make && make install
cd /usr/local/nginx/
/usr/local/nginx/sbin/nginx -c conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload
sed -i '15a stream {\n\tserver{ \n\t\tlisten 143;\n\t\tproxy_connect_timeout 5s;\n\t\tproxy_timeout 5s;\n\t\tproxy_pass mail.cnhbstock.com:143;\n\t\t}\n\tserver{\n\t\tlisten 25;\n\t\tproxy_connect_timeout 5s;\n\t\tproxy_timeout 5s;\n\t\tproxy_pass mail.cnhbstock.com:25;\n\t\t}\n}' /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload
复查配置文件
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
...
stream {
server{
listen 143;
proxy_connect_timeout 5s;
proxy_timeout 5s;
proxy_pass mail.xxxxx.com:143;
}
server{
listen 25;
proxy_connect_timeout 5s;
proxy_timeout 5s;
proxy_pass mail.xxxx.com:25;
}
}
...
查看143和25端口启动状态
[[email protected] ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 94631/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 94631/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6683/sshd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 94631/nginx: master
tcp6 0 0 :::9100 :::* LISTEN 6684/node_exporter
tcp6 0 0 :::22 :::* LISTEN 6683/sshd
kill掉原有的nginx
[[email protected] ~]# ps -ef|grep nginx |grep -v color|awk '{print $2}'|xargs kill -9
配置nginx到systemctl管理
[[email protected] ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx-The High-performance HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl使用
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl restart nginx
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl status nginx
[[email protected] ~]# systemctl status nginx
● nginx.service - nginx-The High-performance HTTP Server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-12-16 08:17:38 CST; 37min ago
Process: 94622 ExecStop=/usr/local/nginx/sbin/nginx -s stop (code=exited, status=0/SUCCESS)
Process: 94629 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Process: 94627 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 94631 (nginx)
CGroup: /system.slice/nginx.service
├─94631 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/ngi...
└─94632 nginx: worker process
Dec 16 08:17:38 localhost.localdomain systemd[1]: Stopped nginx-The High-performance HTTP Server.
Dec 16 08:17:38 localhost.localdomain systemd[1]: Starting nginx-The High-performance HTTP Server...
Dec 16 08:17:38 localhost.localdomain nginx[94627]: nginx: the configuration file /usr/local/ng...ok
Dec 16 08:17:38 localhost.localdomain nginx[94627]: nginx: configuration file /usr/local/nginx/...ul
Dec 16 08:17:38 localhost.localdomain systemd[1]: Started nginx-The High-performance HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
上一篇: JS学习笔记-Iterator
下一篇: 【Linux应用】pthread详解