Today I ran into a problem - it turned out that by mistake the old system administrator, in one very rare case, we had a redirect from the usual 80 port to port 8080.
Because of this, a whole bunch of pages with the address example.com:8080 got into the Yandex index, because the problem has existed for 3 years, and we noticed it only now.
The problem was aggravated by the fact that the server was configured automatically using the ISP manager, which resulted in the sites being available at both example.com and example.com:8080, and taking into account that 5 ip were attached to the server -adrests and about 20 sites rotated on it, reconfigure everything manually to configure Apache and nginx in the correct way (to make Apache listen only 127.0.0.1 and hang on the same port with nginx, and external addresses listen only to nginx) .
All sites that use an ISP manager are potentially susceptible to the problem , so I consider it quite relevant, and decided to publish my decision so that everyone can check and fix it, if necessary.
')
Accordingly, the task was to make “a little blood”:
1. for example.com to work correctly but not open at example.com:8080
2. so that from port 8080 for one specific site go redirect to port 80 in order to preserve the efficiency of the pages that fall into the issuance of Yandex.
Go straight to the answer, without prehistoryA quick googling did not show anything good, most of the methods were similar to the method with iptables proposed
here :
iptables -A INPUT -p tcp -m tcp
The problem is that this method does not work - dmesg gives
ip_tables REDIRECT target: only valid in nat table, not filter.
After a little googling I found an option on the nginx-ru mailing list:
www.lexa.ru/nginx-ru/msg21134.htmlThe variant was this - to move my site from my ip 11.22.33.44:8080 to 127.0.0.1:8080 to apache.conf, to write proxy_pass 127.0.0.1:8080 instead of 11.22.33.44:8080 for my site in nginx.conf, and then add new server to nginx config
server { listen 11.22.33.44:8080; rewrite ^/(.*)$ http://$host:80/$1 redirect; }
The variant basically was similar to the truth, but there was one problem - the Apache stubbornly listened to the port 11.22.33.44:8080, and accordingly did not let the nginx start listening to it.
Then it dawned on me - you can just take it and implement the same redirect, but using apache tools and not nginx.
Just take and add the corresponding VirtualHost to apache2.conf:
<VirtualHost 11.22.33.44:8080> ServerName example.com Redirect 301 / http://example.com/ </VirtualHost>
I tried - and voila, it all worked!
Solution to the problem
Thus, solving the problem "
how to make a redirect from port 8080 to port 80 ", provided that you have debian, nginx, apache and everything is set up by the isp manager for example.com site with ip 11.22.33.44, consists of four simple steps :
1. In the Apache config (/etc/apache2/apache2.conf) we change all entries
Virtual Host 11.22.33.44:8080
on
VirtualHost 127.0.0.1:8080
2. Add Apache (/etc/apache2/apache2.conf) to the Apache config with a redirect:
<VirtualHost 11.22.33.44:8080> ServerName example.com Redirect 301 / http://example.com/ </VirtualHost>
3. In the nginx config (/etc/nginx/nginx.conf) we change all entries
proxy_pass http:
on
proxy_pass http:
4. restart apache, restart nginx
/etc/init.d/apache2 restart /etc/init.d/nginx restart