Change Default Apache Port in Plesk

Community support for Plesk, CPanel, WebMin and others with insight from two of the founders of Plesk. Ask for help here! No question is too simple or complicated. :-)
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Change Default Apache Port in Plesk

Unread post by dayo »

Struggling to change the default port for Apache in Plesk.

I know I can change the "Listen" directive in httpd.conf but this does not reflect in the <virtualhost IP:80> entry in httpd.include for the specific domains and I know that directly changing it there is useless as Plesk will overwrite this sooner or later.

Nosing around the conf.d directory, I notice all of the plesk generated files have 80 in them and that this remains so after changing the "Listen" directive in httpd.conf and restarting Apache which seems to suggest that port 80 may be hard coded into the Plesk php files.

I hope this is not the case and that it is possible to change this. It would be nice if there was a place where one could enter a port number and have it go everywhere it should.

Looking forward to receiving some help

Thanks
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Re: Change Default Apache Port in Plesk

Unread post by scott »

You could always make some kind of script to re-write the configs using the Event Manager
breun
Long Time Forum Regular
Long Time Forum Regular
Posts: 2813
Joined: Sat Aug 20, 2005 9:30 am
Location: The Netherlands

Re: Change Default Apache Port in Plesk

Unread post by breun »

Why do you want Apache on another port? Maybe you can use a firewall rule to redirect traffic on another incoming port to Apache or something?
Lemonbit Internet Dedicated Server Management
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

breun wrote:Why do you want Apache on another port? Maybe you can use a firewall rule to redirect traffic on another incoming port to Apache or something?
Thanks

Trying to run Nginx on Port 80 and proxying to Apache so IP Table redirect would work for me.
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

scott wrote:You could always make some kind of script to re-write the configs using the Event Manager
Seems like a lot of effort for a relatively simple requirement and seems to confirm my suspicion that Port 80 is hard coded into the binaries and encrypted php files.

I guess I should have realised this was a major undertaking in Plesk after a long hard google search yielded nothing.

I prefer managing Plesk due to the more logical interface but been thinking of switching to CPanel for the ease of actually getting things done once one gets over the not so well laid out interface.

Thanks
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Re: Change Default Apache Port in Plesk

Unread post by scott »

Yes, it is hard coded but its really trivial to change it with a script using the event manager. Something like:

perl -p -i -e "s[Listen 80][Listen 8080]g" <filename>

would do the trick. You can trigger those events on all sorts of things, not just domain creation. You can fire that kind of thing on email address creation (useful for custom anti-spam systems), new domains/updates to existing domains/deletes. When you look at it from the top down its extremely powerful, you can more or less rewrite anything on the system however you like it.
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

scott wrote:Yes, it is hard coded but its really trivial to change it with a script using the event manager. Something like:

perl -p -i -e "s[Listen 80][Listen 8080]g" <filename>

would do the trick. You can trigger those events on all sorts of things, not just domain creation. You can fire that kind of thing on email address creation (useful for custom anti-spam systems), new domains/updates to existing domains/deletes. When you look at it from the top down its extremely powerful, you can more or less rewrite anything on the system however you like it.
I guess this can be done. but not so trivial though
1) I need to make sure I cover all the files in conf.d
2) I'll need to write a script to recursively run through the domains and subdomains in /var/www/vhosts to change the httpd.include files (Some start help on this would be nice)
3) I need to make sure I cover any other files outside conf.d (I hope there are none)
4) I'll need to make sure I cover every possible event that could trigger a rewrite or creation of any of these files
5) I'll have to hope future versions of Plesk to do add new events that rewrite these files

It would have been nice if the Apache port was loaded in a variable accessibile directly in Plesk ... but that'll be too easy I guess. Sigh.

I could give the scripting a shot but the steps to cover are a bit much and the potential failure points are many. Tips and pointers would be appreciated .. particularly on the recursive directory scanner.
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

dayo wrote:Tips and pointers would be appreciated .. particularly on the recursive directory scanner.
Google suggests this might work...

Code: Select all

#!/bin/bash
FILE="httpd.include"
FIND=":80"
REPLACE=":81"
cd /var/www/vhosts
find . -name $FILE -print0 | xargs -0p perl -pi -w -e "s/$FIND/$REPLACE/g;"
Just now need to gather a list of candidate events and files to change other stuff.
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Re: Change Default Apache Port in Plesk

Unread post by scott »

Its a pretty powerful feature, since you've basically got the ability to retweak all the configs based on different events (new, update, delete) with a bunch of different variables available, like domain name, or email address just to name a few.

So for example if you wanted to just force the different port across every domain this might do the trick:

find /var/www/vhosts/ -name httpd.include -exec perl -p -i -e "s[:80][:8080]g" {} \;
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

Thanks

I modified my script to

Code: Select all

#!/bin/bash
MY_FILEPATH="/var/www/vhosts"
MY_FILE="httpd.include"
MY_FIND=":80"
MY_REPLACE=":81"
find $MY_FILEPATH  -name $MY_FILE -exec perl -p -i -e "s[$MY_FIND][$MY_REPLACE]g" {} \;
service httpd restart
After bristling at hardcoded stuff, I thought it would better to use variables. I am hoping to change the variables to $1, $2 etc and just call the same file with a list of four different inputs each time. I added the httpd restart as I figured this was needed to actually read the new stuff in.

Seems this should also work for zz010_psa_httpd.conf.

So part way there ... now need to get the relevant event triggers and other files.

With regards to the event triggers, I suppose I have to give the the lowest priority and that this would make them run last. I have found links for event triggers for previous versions of Plesk in the past .... I assume they are fairly constant and don't change radically as I have never found similar for Plesk 9.2.x.
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Re: Change Default Apache Port in Plesk

Unread post by scott »

The only changes that I know of for the event manager across version has been they've added more variables, or more classes of events. So it should be a pretty consistent across updates.

You might not need that httpd restart either. plesk will batch those together via websrvmng so you dont end up restarting it 1 * n domains each time someone makes an update. Also by default plesk has a thottle control that will limit this to once every 900 seconds by default (user configurable in "settings"). I can see a case where if your users make a lot of domain changes you could DoS yourself with all those restarts.
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

I wasn't sure whether the event is triggered after completion of the actual action in which case the parameters would have been read in already or not
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

Hi

Got a different problem. I ran the port change command...
1. On the httpd.include files for each domain
2. On zz010_psa_httpd.conf
3. Changed the listen directive in httpd.conf
This went ok and I verified they all changed ok.

However when I tried to restart httpd, I get the following

Code: Select all

[warn] VirtualHost IP_1:80 overlaps with VirtualHost IP_1:80, the first has precedence, perhaps you need a NameVirtualHost directive
[warn] VirtualHost IP_2:80 overlaps with VirtualHost IP_2:80, the first has precedence, perhaps you need a NameVirtualHost directive
[warn] VirtualHost IP_3:80 overlaps with VirtualHost IP_3:80, the first has precedence, perhaps you need a NameVirtualHost directive
The weird thing is that there is nothing with IP:80 in any of the config files and when I tried a change back to Port 80 and restarted httpd, I started getting the same messages but with Port 81 instead.

I added "NameVirtualHost *:80" to the list of NameVirtualHost IP:81 in zz010_psa_httpd.conf as a test, I got a message saying there where no virtual hosts at Port 80.

I have not yet bound anything to Port 80 but still surprised that after changing the Apache Port, I am getting warning messages related to the old location.

Any insight will be appreciated.

Thanks
scott
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 8355
Joined: Wed Dec 31, 1969 8:00 pm
Location: earth
Contact:

Re: Change Default Apache Port in Plesk

Unread post by scott »

I know those are also listed in the httpd.include files in each domain, Id double those and/or any vhost.conf files that reference it
dayo
Forum Regular
Forum Regular
Posts: 158
Joined: Sun Jul 12, 2009 1:33 pm

Re: Change Default Apache Port in Plesk

Unread post by dayo »

scott wrote:I know those are also listed in the httpd.include files in each domain, Id double those and/or any vhost.conf files that reference it
Hi I forgot to post an update.

The error message was because there are other httpd conf files that have virtual hosts defined and I had only changed zz010_psa_httpd.conf. I finally ran netstat -tulpn| grep :80 in there to get a list of them and then changed the ports on those as well so that the error message has gone.

Other problems have arisen since but still trying to get my head around them. Basically, I get the following error when I try to view anything.

Code: Select all

Network Error (tcp_error)

A communication error occurred: "Connection refused"
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.

For assistance, contact your network support team. 
This might be related to my Nginx config. I'll need to dig in and see why
Post Reply