Solving the problem with the appearance of port 8080 in ISP manager (setting up a redirect to port 80)
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 they noticed it only now.
The problem was aggravated by the fact that the server was configured automatically using the ISP manager, which led to the fact that the sites were accessible both at example.com and at example.com:8080, and taking into account that 5 ip were connected to the server -addresses and about 20 sites turned on it, reconfiguring everything manually to configure Apache and nginx in the correct way (to make Apache listen only to 127.0.0.1 and hang on the same port with nginx and only nginx listen to external addresses) was not possible . All sites that use the ISP manager are potentially affected by the problem , so I think it is quite relevant, and decided to publish my solution so that everyone also checked and corrected, if necessary.
Accordingly, the task was to do “little blood”:
1. so that example.com works correctly, but does not open at example.com:8080
2. so that a redirect to port 80 goes from port 8080 for one particular site in order to maintain the functionality of the pages that got Yandex.
Go straight to the answer, without a background A
quick google 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 --dport 8080 -j REDIRECT --to-ports 80The problem is that this method does not work - dmesg produces
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.html
The option was this - to upload my site in apache.conf from my ip 11.22.33.44:8080 to 127.0.0.1:8080 , in nginx.conf respectively register proxy_pass 127.0.0.1:8080 instead of 11.22.33.44:8080 for my site, and then add a new server to the nginx config
server {
listen 11.22.33.44:8080;
rewrite ^/(.*)$ http://$host:80/$1 redirect;
}The option, in principle, was similar to the truth, but there was one problem - the Apache persistently listened to port 11.22.33.44:8080, and accordingly did not allow nginx to start listening to it.
Then it dawned on me - you can just take it and implement the same redirect, but using apache and not nginx.
Just take and add the corresponding VirtualHost to apache2.conf:
ServerName example.com
Redirect 301 / http://example.com/
I tried it - and voila, it all worked!
Solution
Thus, the solution to the problem " how to redirect from port 8080 to 80 ", provided that you have debian, nginx, apache and all this is configured by the isp-manager for example.com with ip 11.22.33.44, consists of four simple steps :
1. In the Apache config (/etc/apache2/apache2.conf) we change all occurrences
Virtual Host 11.22.33.44:8080 on the VirtualHost 127.0.0.1:80802. Add a new VirtualHost with a redirect to the Apache config (/etc/apache2/apache2.conf):
ServerName example.com
Redirect 301 / http://example.com/
3. In the nginx config (/etc/nginx/nginx.conf) we change all occurrences
proxy_pass http://11.22.33.44:8080on the
proxy_pass http://127.0.0.1:80804. restart apache, restart nginx
/etc/init.d/apache2 restart
/etc/init.d/nginx restart