Click Tracking IP Problem
I have installed Postal server on postal.mozget.me & i wanted to track postal emails but failed to do so.
Hosting provider - Microsoft Azure RAM - 7GB Server - Ubuntu Ip - 52.237.75.66 Secondary Ip - 52.237.75.84 As you stated in the Documentation
I created an "A" Type with host track.mail.mozget.me and ip 52.237.75.84 but it doesn't seem to work.
I also created a CNAE with host click.mozget.me and ALIAS track.mail.mozget.me.
Maybe i'm not getting how to add that secondary ip to my Main Virtual Machine.
I'm aslo confused, Do i have to open PORT 5010 and 5011? as you stated "To facilitate the logging & redirection, Postal runs a separate web server process that listens on ports 5010 (for HTTP) and 5011 (for HTTPS). "
I even enabled the fast server with these detail
fast_server:
enabled: true
bind_address: 52.237.75.84
Now in the /etc/nginx/sites-enabled/default i added these details
server {
listen [::]:80;
listen 52.237.75.84:80;
server_name postal.mozget.me;
return 301 https://$host$request_uri;
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
}
server {
listen [::]:443 ssl;
listen 52.237.75.84:443 ssl;
root /opt/postal/app/public;
server_name postal.mozget.me;
ssl_certificate /etc/letsencrypt/live/postal.mozget.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/postal.mozget.me/privkey.pem;
Please Let me know where I'm Wrong, Or you can have access to my server and have a look
I think the configuration is a little wrong, please remove the following lines listen [::]:80; and listen [::]:443 ssl; and change the IP address to 52.237.75.66.
Nginx is only for securing access to the admin web interface, the click tracking looks after itself.
after changing the ip address to 52.237.75.66:80 and 52.237.75.66:443 in /etc/nginx/sites-enabled/default file. I'm Receiving an error
Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
Here is the details
-- Unit nginx.service has begun starting up.
Nov 23 11:35:28 MAIL nginx[72069]: nginx: [emerg] bind() to 52.237.75.66:80 fail [emerg] bind() to 52.237.75.66:80 failed (99: Cannot assign requested address) configuration file /etc/nginx/nginx.conf test failed
Nov 23 11:35:28 MAIL nginx[72069]: nginx: configuration file /etc/nginx/nginx.co
Nov 23 11:35:28 MAIL systemd[1]: nginx.service: Control process exited, code=exited service: Control process exited, code=exited status=1
Nov 23 11:35:28 MAIL systemd[1]: Failed to start A high performance web server a
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
Nov 23 11:35:28 MAIL systemd[1]: nginx.service: Unit entered failed state.
Nov 23 11:35:28 MAIL systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 23 11:35:28 MAIL sudo[72051]: pam_unix(sudo:session): session closed for use
After changing it to again 0.0.0.0:80 and 0.0.0.0:443, Server was able to start.
Oh hang on I misread what you said
Now in the /etc/nginx/sites-enabled/default i added these details
You should remove those two server blocks, the only things in that file should be for the main app. After removing those blocks you should restart postal and use sudo netstat -lnp to confirm that the click tracking has managed to bind itself to the correct IP address.
What Do you actually Mean by removing two blocks? Because if remove those two blocks nothing would be left behind
Here is the full configuration in that file
server {
listen 0.0.0.0:80;
server_name postal.mozget.me;
return 301 https://$host$request_uri;
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
}
server {
listen 0.0.0.0:443 ssl;
root /opt/postal/app/public;
server_name postal.mozget.me;
ssl_certificate /etc/letsencrypt/live/postal.mozget.me/fullchain.pem; # managed$
ssl_certificate_key /etc/letsencrypt/live/postal.mozget.me/privkey.pem; # manag$
# Generate using: openssl dhparam 4096 -out /etc/ssl/dhparam.pem
# ssl_dhparam /etc/ssl/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA512:EECDH+E$
location / {
client_max_body_size 50M;
try_files $uri $uri/index.html $uri.html @puma;
}
location /assets {
add_header Cache-Control max-age=3600;
}
location @puma {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://127.0.0.1:5000;
}
I tried removing the listen line from both of blocks and i restarted the postal and nginx successfully. Here is what i got after netstat -lnp
sudo netstat -lnp
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:22 0.0.0.0:* LISTEN 1913/sshd
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 26411/[postal] web.
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 10887/beam.smp
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 11870/mysqld
tcp 0 0 127.0.0.1:783 0.0.0.0:* LISTEN 53539/spamassassin.
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 74212/nginx -g daem
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 10981/epmd
tcp6 0 0 :::22 :::* LISTEN 1913/sshd
tcp6 0 0 :::25 :::* LISTEN 72832/[postal] smtp
tcp6 0 0 :::5672 :::* LISTEN 10887/beam.smp
tcp6 0 0 ::1:783 :::* LISTEN 53539/spamassassin.
tcp6 0 0 :::4369 :::* LISTEN 10981/epmd
udp 0 0 0.0.0.0:68 0.0.0.0:* 129768/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 129585/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 129467/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 127992/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 115956/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 115787/dhclient
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 13567 1/init /run/lvm/lvmpolld.socket
unix 2 [ ACC ] STREAM LISTENING 98657 26405/app) /tmp/postal/pids/procodile.sock
unix 2 [ ACC ] STREAM LISTENING 85648 11870/mysqld /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 24466 2159/systemd /run/user/1000/systemd/private
unix 2 [ ACC ] STREAM LISTENING 13489 1/init /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 18616 1/init /run/snapd.socket
unix 2 [ ACC ] STREAM LISTENING 18615 1/init /var/lib/lxd/unix.socket
unix 2 [ ACC ] STREAM LISTENING 18618 1/init /run/snapd-snap.socket
unix 2 [ ACC ] STREAM LISTENING 18620 1/init /var/run/dbus/system_bus_socket
unix 2 [ ACC ] SEQPACKET LISTENING 13501 1/init /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 18288 1438/iscsid @ISCSIADM_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 18623 1/init /run/uuidd/request
unix 2 [ ACC ] STREAM LISTENING 19394 1580/nscd /var/run/nscd/socket
unix 2 [ ACC ] STREAM LISTENING 18626 1/init /run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 19396 1580/nscd /var/run/.nscd_socket
unix 2 [ ACC ] STREAM LISTENING 13510 1/init /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 13562 1/init /run/lvm/lvmetad.socket
can you send your postal.yml (minus confidential information of course)
web:
# The host that the management interface will be available on
host: postal.mozget.me
# The protocol that requests to the management interface should happen on
protocol: https
fast_server:
# This can be enabled to enable click & open tracking on emails. It is disabled by
# default as it requires a separate static IP address on your server.
enabled: true
bind_address: 52.237.75.66
general:
# This can be changed to allow messages to be sent from multiple IP addresses
use_ip_pools: false
main_db:
# Specify the connection details for your MySQL database
host: 127.0.0.1
username: *********
password: ********
database: postal
message_db:
# Specify the connection details for your MySQL server that will be house the
# message databases for mail servers.
host: 127.0.0.1
username: *******
password: ********
prefix: postal
rabbitmq:
# Specify the connection details for your RabbitMQ server.
host: 127.0.0.1
username: ******
password: *******
vhost: /postal
dns:
# Specifies the DNS record that you have configured. Refer to the documentation at
# https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration for further
# information about these.
mx_records:
- mail.mozget.me
smtp_server_hostname: mozget.me
spf_include: spf.mail.mozget.me
return_path: rp.mail.mozget.me
route_domain: routes.mail.mozget.me
track_domain: track.mail.mozget.me
smtp:
# Specify an SMTP server that can be used to send messages from the Postal management
# system to users. You can configure this to use a Postal mail server once the
# your installation has been set up.
host: mozget.me
port: 25
username: ********** # Complete when Postal is running and you can
password: ********** # generate the credentials within the interface.
from_name: Mozget
from_address: [email protected]
rails:
# This is generated automatically by the config initialization. It should be a random
# string unique to your installation.
secret_key: a38614a1a4c************79$
spamd:
enabled: true
host: 127.0.0.1
port: 783
fast_server > bind_address should be the IP address you want to use for click tracking and the other IP address should be used in the Nginx configuration to access the web interface on so make sure you have the addresses in the right place and restart the services and hopefully that should do the trick?
Also you can try running ip a to see what ip addresses your server has detected. I don't know azure but it might be that you only have internal IPs on the server and azure maps them to public IPs later.
That's the real problem. I just don't know where to start from to add that secondary ip into main virtual machine.
I suggest that you consult the azure documentation (unless someone who knows it is able to chime in) and come back later.
Follow this to add a new ip address in Microsoft Azure https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-multiple-ip-addresses-portal#coreadd You have to add a new public ip address, not the private ip address.
After that make sure that the ip is attached to NIC in your VM. Type command ip a to check.
Use that ip to bind address for fast server.
fast_server:
# This can be enabled to enable click & open tracking on emails. It is disabled by
# default as it requires a separate static IP address on your server.
enabled: true
bind_address: YOUR_NEW_ATTACHED_IP
Restart postal server by sudo postal restart.
Thanks for this Article, Now the IP is Working but when I'm opening that IP, It is showing the postal login page. Even the cname is also showing that login page. I think the listen parameter in /etc/nginx/sites-enabled/default is causing the hole problem. because the nginx server is confused which ip to handle and show the data.
Now the problem is if i add
listen 0.0.0.0:80 and listen 0.0.0.0:443 ssl;
the server redirects all request to postal login page
if i add the primary ip such as
listen 52.237.75.66:80; and listen 52.237.75.66:443 ssl;
the nginx server starts giving error and does not restart.
any other way to solve this problem?
Can you share the results of ip a to see what IP addresses are on your server?
Primary IP 52.237.75.66 Secondary New IP - 52.237.72.203
Here is the output of ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0d:3a:a3:a1:b0 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.4/24 brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet 10.0.0.7/24 brd 10.0.0.255 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::20d:3aff:fea3:a1b0/64 scope link
valid_lft forever preferred_lft forever
10.0.0.4 is Private IP of primary IP 10.0.0.7 is Private IP of secondary IP
Output of netstat -nlp | grep nginx
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 93242/nginx -g daem
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 93242/nginx -g daem
So 10.0.0.4 is either equal to 52.237.75.66 or 52.237.72.203 with 10.0.0.7 equal to the other one.
You need to use 10.0.0.4 and 10.0.0.7 in postal.yml and your nginx.
If you can't figure it out from your azure control panel, you can presumably just try one combination and see what happens.
I added listen 0.0.0.0:80 as 10.0.0.4:80 and now the secondary ip is showing "The connection to the server was reset while the page was loading". and if put it as 10.0.0.7:80 then it shows postal login page.
Why are you listening on all ip interfaces when you have a primary ip assigned to redirect to your webui. Your code
server {
listen 0.0.0.0:80;
server_name postal.mozget.me;
return 301 https://$host$request_uri;
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
}
server {
listen 0.0.0.0:443 ssl;
Change 0.0.0.0 to your primary ip for both ports 80 and 443. Let it listen on ipv6 instead. Replace you nginx conf with this
server {
listen [::]:80;
listen 52.237.75.66:80;
server_name postal.mozget.me;
return 301 https://$host$request_uri;
server {
listen [::]:443 ssl;
listen 52.237.75.66:443 ssl;
root /opt/postal/app/public;
server_name postal.mozget.me;
ssl_certificate /etc/letsencrypt/live/postal.mozget.me/fullchain.pem; # managed$
ssl_certificate_key /etc/letsencrypt/live/postal.mozget.me/privkey.pem; # manag$
# Generate using: openssl dhparam 4096 -out /etc/ssl/dhparam.pem
# ssl_dhparam /etc/ssl/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA512:EECDH+E$
location / {
client_max_body_size 50M;
try_files $uri $uri/index.html $uri.html @puma;
}
location /assets {
add_header Cache-Control max-age=3600;
}
location @puma {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://127.0.0.1:5000;
}
Make sure for an entry in /etc/hosts for 52.237.75.66 postal.mozget.me
Change the bind address for fast server to secondary public ip in postal.yml and make sure all dns records are configured properly.
You can disable ipv6 forwarding by entering this to the end of /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Run sysctl -p after that.
@zeeshanjamal16 That's the problem i Posted above that whenever i make nginx listen 52.237.75.66 or the secondary ip i get error saying
sudo /etc/init.d/nginx restart
[....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
failed!
I have already posted that error in above post.
& whenever i added private ip in listen, it didn't gave me any error.
Reference of Ip http://res.cloudinary.com/cb1f716b3e979937/image/upload/v1511461264/Screen_Shot_2017-11-23_at_11.49.11_PM_mlml5z.png
DNS Records http://res.cloudinary.com/cb1f716b3e979937/image/upload/v1511461446/Screen_Shot_2017-11-23_at_11.53.42_PM_twtmjc.png
Nginx
http://res.cloudinary.com/cb1f716b3e979937/image/upload/v1511461509/Screen_Shot_2017-11-23_at_11.54.45_PM_lwokiw.png
http://res.cloudinary.com/cb1f716b3e979937/image/upload/v1511461578/Screen_Shot_2017-11-23_at_11.55.51_PM_s0bhra.png
With all these configuration i showed you, Now the connection of tracking domain is being reset by server
http://res.cloudinary.com/cb1f716b3e979937/image/upload/v1511461666/Screen_Shot_2017-11-23_at_11.57.29_PM_yf1eay.png
You need to use 10.0.0.4 and 10.0.0.7 in
postal.ymland your nginx.
Your server is only aware of those two IP addresses so you can't use the other two in your configuration.
Make nginx listen on 10.0.0.7 and set the fast_server > bind_address to 10.0.0.4, restart everything and see if thats sorted you.