PDA

View Full Version : Can You Use Apache / Http On A Different Port?



designers_hub
27th August 2005, 07:15 PM
On mac os x you can enable web sharing.

Optus blocks the use of port 80. Is there a way i can change the port apache uses so that i can enable web sharing?

on my router i tried redirecting incoming traffic (lets say port 1000) to port 80 on the mac. didn't work.

If is there is no way around this. Is there another way i can allow access to a folder on my computer for the internet. (using a web browser). I can use ftp servers etc, but i want to turn my mac into the server, its more easy and i don't need to suffer the slow upload speeds.

Danamania
27th August 2005, 07:19 PM
Originally posted by designers_hub@Aug 27 2005, 07:15 PM
On mac os x you can enable web sharing.

Optus blocks the use of port 80. Is there a way i can change the port apache uses so that i can enable web sharing?

You can edit the file on osx as root:

/etc/httpd/httpd.conf

and look for this segment:



# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
#Listen 3000
#Listen 12.34.56.78:80


It shows how to define which port or IP+port apache should listen on.

Just add a line like this:



Listen 1000


and turn off then re-turn on web sharing, and apache will be listening on port 1000 :)

dana

designers_hub
27th August 2005, 07:21 PM
I found this:

to show all hidden files, type this in terminal:
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

to change back:
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder


sounds all good, but it keeps saying i cannot save the file (after the change)

Danamania
27th August 2005, 07:27 PM
Originally posted by designers_hub@Aug 27 2005, 07:21 PM
sounds good, but i can't find that file.

is it hidden?
You won't be able to get to it from the finder, by default. Editing it from the terminal is the go

just open a terminal window and do:



sudo pico /etc/httpd/httpd.conf


then enter your password, and you should come up with a terminal editor filled with the text of the httpd.conf file. use ctrl-W and enter the text 'listen' (no quotes) - what you type will appear in the black bar near the bottom of the terminal window.

Then type the "Listen 1000" line in a blank line there (don't put a # in front of it)

ctrl-X will exit the editor. it'll ask if you want to save it, hit 'Y' for yes, then it'll ask the filename to write. just hit enter and you'll have saved your apache config.

dana

Danamania
27th August 2005, 07:28 PM
Originally posted by designers_hub@Aug 27 2005, 07:21 PM
FANTASIC! Thanks

BTW i neat little trick

to show all hidden files, type this in terminal.

defaults write com.apple.finder AppleShowAllFiles TRUE

killall Finder



to change back

defaults write com.apple.finder AppleShowAllFiles FALSE

killall Finder
Good to see it worked :)

dana

W2ttsy
27th August 2005, 07:32 PM
fire up the terminal, and type in the following line


sudo pico etc/httpd/httpd.conf

youll have to enter your admin password.

then it will fire up pico (text editor) with the apache conf file.

you can search thru your document by pressing control and W, entering in a string and pressing return. i recommend using "Listen" as the string.

then edit your file.

to write out the modified file, press control and O and then press enter
then press control and X to exit.

then type
sudo apachectl graceful to restart the server.

W2ttsy

e:f,b

designers_hub
27th August 2005, 07:43 PM
it can't find the string of code.

umm, nothing comes up in the terminal. The pico comes up, but theres nothing in the text area

can you change the file to work on port 5903 and upload it or something?

the terminal is not picking up any text inside the httpd.conf file

Danamania
27th August 2005, 07:55 PM
Originally posted by designers_hub@Aug 27 2005, 07:43 PM
it can't find the string of code.

umm, nothing comes up in the terminal. The pico comes up, but theres nothing in the text area
can you paste here the exact line you're typing into the terminal in order to edit it?


dana

designers_hub
27th August 2005, 07:56 PM
Listen

Danamania
27th August 2005, 07:59 PM
Originally posted by designers_hub@Aug 27 2005, 07:56 PM
Listen
That won't edit the file - you need to do:



sudo pico /etc/httpd/httpd.conf

make sure all slashes are included, and use httpd (with the d on the end) not just http

designers_hub
27th August 2005, 08:03 PM
ok kool. now lets say i want it on port 1000

#Listen 3000
#Listen 12.34.56.78:80

will that become:
#Listen 1000
#Listen 12.34.56.78:1000

???

Danamania
27th August 2005, 08:07 PM
Originally posted by designers_hub@Aug 27 2005, 08:03 PM
ok kool. now lets say i want it on port 1000

#Listen 3000
#Listen 12.34.56.78:80

will that become:
#Listen 1000
#Listen 12.34.56.78:1000

???
Nah - they're just examples of how to use the "Listen" directive. anything with a # before it is a comment, and doesn't affect apache in any way. You have to edit that section of the file so it says:



#Listen 3000
#Listen 12.34.56.78:80
Listen 1000


in other words, all you need to do is add an entirely new line underneath with "Listen 1000" as text without a # in front of it. Technically you could have put it in a single line at the top of the file, or at the end, or anywhere in front as long as it said "Listen 1000" without a # in front. It's just better to put it close to the area where it's all explained, so that if you come back to it later it'll be in a sane place and you won't need to hunt around the apache config file for it :)

dana

designers_hub
27th August 2005, 08:12 PM
sweet, its working.

when i type 192.168.0.2:1000/~user it goes in.

but thats my network url. i don't know if its my router. I did the port forwarding TCP 1000...

is there something i'm missing?

Quamen
27th August 2005, 08:13 PM
Damn I was too slow. In order to get in from the outside world you will need to find out your external IP address. http://www.whatismyip.com/ can help you there. So you would use that IP:1000 and then forward port 1000 to your mac with the server on it.


try using vim instead. But I suggest you leave out the "sudo" part of the command until you know you can go in and edit the file without screwing things up :)

sudo vim /etc/httpd/httpd.conf

then do "/Listen" without the quotes. This will get you to the part of file you need to edit.


# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
#Listen 3000
#Listen 12.34.56.78:80


Use the arrow keys to navigate to the # infront of "#Listen 3000". Then press fn+delete to remove the hash. Then press escape.

Then move the cursor over to the number 3 and press "r" for replace, and press 1.

This will replace the 3 with a 1. Now hit escape again to return to command mode. Then type in ":wq" without the quotation marks to write the file and quit vim. If you&#39;re not using the sudo command you&#39;ll have to quit by using the ":q&#33;" command and repeat everything using sudo.

designers_hub
27th August 2005, 08:20 PM
lol... yeah i&#39;m suprised at the amount of responses.

thanks everyone, i&#39;m almost there.

my mac is configured correctly.

I think its just my router now. I did forward port 1000 (inbound port) to my mac (192.168.0.2) at port 1000 (private port). TCP btw.

Danamania
27th August 2005, 08:28 PM
Originally posted by designers_hub@Aug 27 2005, 08:20 PM
I think its just my router now. I did forward port 1000 (inbound port) to my mac (192.168.0.2) at port 1000 (private port). TCP btw.
Aye, sounds like a router issue now - which router are you using? If someone else reads this thread and knows about your router&#39;s peculiarities they may be able to help. Perhaps even screenshots of your router&#39;s configuration page where you&#39;ve edited the port forwarding info might let someone who&#39;s cluey enough pick up why it&#39;s not working.

dana

Quamen
27th August 2005, 08:29 PM
Good luck in getting it going then. Actually I would suggest you use a much higher port. something above 5000.

Ports 1 to 1023 are reserved ports. 1024-5000 are ephemeral client ports (short lived ports).

5000 and above are for other services.

W2ttsy
27th August 2005, 08:33 PM
terminal should look like this when you type in the first command

http://img368.imageshack.us/img368/7438/picture97ce.png

when you press enter, you will be prompted for the admin password. hit enter and you will be presented with this screen

http://img368.imageshack.us/img368/8900/picture108xl.png

as you can see, ive already stuck the search string in. i did this by pressing control W

next you will need to edit the listen port and IP. im assuming you can remove the hashes and go from there.

then write out the file by pressing control O

then press enter to save, and then control X to exit.

you will then need to restart apache web server.

you will need to type in sudo apachectl graceful

your terminal should look like this

http://img370.imageshack.us/img370/1162/picture126lf.png

and after you press enter, it should look like this

http://img370.imageshack.us/img370/4055/picture137tj.png

hope this helps

W2ttsy

designers_hub
27th August 2005, 08:40 PM
Wow W2ttsy thanks for all that effort. Unfortunately i already sloved that.

but still, i&#39;m sure many people will find this thread helpful.

*****************

I am using port 5903. I have a belkin wireless router. And i have attached a screenshot.

btw. the fields are too small, but they all say "5903".

W2ttsy
27th August 2005, 08:49 PM
ok, im rather annoyed that i keep getting caught behind here. haha..

as for routers, well im running an airport network at home.

i forward port 80 from the WWW to my home machine 10.0.*.*

the private and public ports are 80, and the private ip is that of my above. * out the last 2 numbers for security.

in the apache file, you will need to set the Listen IP to that of your local host. ie 192.168.0.2

and then the port number of something over 5000 (seems you are conflicting with a service called cadlock2

i suggest looking at this (http://www.iana.org/assignments/port-numbers) site for more info on available port numbers.

your router shuold interpret wwwIP:port number as the port for apache on the server.

have you hard restarted your router? sometimes routers wont restart unless you force them to with your config software (ie: airport admin) or turn them off, wait a minute and then turn them on.

might want to PM iSlayer, hes done a bit of fiddling with port mapping.

W2ttsy

Quamen
27th August 2005, 08:50 PM
I had another thought. You may not be able to check if it&#39;s working yourself from within your network. Get a friend to try and connect to your server from their house. Alternatively post here (or via PM to myself or another user) the address to access your website.

W2ttsy
27th August 2005, 08:55 PM
i was just thinking. does apache need to be modified?

surely the NAT on the router would turn all traffic coming in from abirtrary port (ex: 8420) into port 80?

just by setting external port to 8420 and internal port to 80...?

just a thought...

W2ttsy

EDIT:

tested that idea, and it works a treat.

to see for yourself. go here with the new port number (http://150.101.111.139:8420) and then to here using port 80 (http://150.101.111.139)

so the above method works.

i left apache unchanged, and just did a redirect on my ports in the admin panel for my router.

so it should look like public port is port number, private address is IP of server and private port is 80

yay. we all learnt something :D

Danamania
27th August 2005, 09:02 PM
Some good news...

as a moderator I get to see your IP - I just tried to load

http://youripaddress:5903/

and it brought up the usual default apache page. It seems to be working ok

did you have a specific ~user that we can try to test if it&#39;s all 100% (and that I&#39;m actually going to the right server. Just in case :D

dana

W2ttsy
27th August 2005, 09:12 PM
just a bit off topic. ive always run a seperate dev folder outside my user folder with read and limited write priveledges. that way there is no /~user to worry about.

if youre interested in setting that up, then id be happy to guide you thru it.

W2ttsy

designers_hub
27th August 2005, 09:31 PM
i got my friend the try it out too. and it works.

how come i can&#39;t see it? LOL, is that normal. maybe the router is getting confused since i&#39;m trying to acces my own computer

w2ttsy, your right, and i was thinking on the same line as well... looks like we didn&#39;t need to change the port and all that stuff. it was a simple router misunderstanding.

its all fine now. i&#39;ll just remember to change my ip to my network ip when on the host server.

Quamen
27th August 2005, 09:54 PM
Originally posted by designers_hub@Aug 27 2005, 09:31 PM
how come i can&#39;t see it? LOL, is that normal.
Yes. You can&#39;t access your external address from inside. That&#39;s what your internal address is for.

It would be like trying to ring your front door bell from your kitchen. Doesn&#39;t really make sense does it?

W2ttsy
27th August 2005, 09:56 PM
just back at quamen here:

should work from inside the network tho, as thats how i tested it. both on the machine the router was pointing to and another machine also on the network.

i can access my machine from its internal and external addresses (thru safari). works fine for me.. but as a rule, its always best to use internal IP or 127.0.0.1 if you using the localhost.

as for it working, well go you. :thumbup:

in regards to limiting access, you can do like i do, and make a new folder outside your use folder. i put it in Library and then give it f all privledges. or you can limit stuff in apache, but thats a bit more tricky and interesting.

id be happy to help you tho, if you would like to set up a restricted area...

w2ttsy

designers_hub
27th August 2005, 09:57 PM
ahahhaha...

well everything is working all thanks to you guys&#33;

i&#39;ve been meaning to do this for a very very long time. so THANKS A MILLION&#33;&#33;&#33;

does anyone know a program which can restrict access on this folder? i&#39;d rather use a mac application rather than a php script. any clues? i know you can change the premission, but about about making user accounts?

Quamen
28th August 2005, 12:24 AM
In what way do you want to restrict access? I can think of a few ways of doing it.

One is to restrict access based on the users domain. So for instance only allow connection from within say rmit university&#39;s domain rmit.edu.au.

Or you could set up basic authentication on the folder itself so that the user needs to put in a name and password in order to access the server.

Both of these methods can be done using apache itself and a few other text files.

W2ttsy I&#39;m not sure why it is that accessing your external IP doesn&#39;t seem to work from within the network. The problem isn&#39;t that it cannot be done, the problem is that you can get situations where it appears to be working when it isn&#39;t. ie on one setup I had I could access my webserver using both the internal and the external IP addresses but nobody outside my network could access the webserver using the external IP address. It wasn&#39;t until I started sending people the link that I realised the setup wasn&#39;t working properly.

W2ttsy
28th August 2005, 12:43 PM
well i was thinking that you could just use netinfo manager to create a new user that runs all the time, but has no priveledges. in fact, i believe from panther onwards, there is a mysql user for this exact reason.

you can then limit apache to only work using that user, and anything inside that user is available to public domain.

if you want to arrange some sort of user system where you are hosting for multiple users (example: ISP users webspace) then you may want to look at getting into a PHP/ASP/JSP/CFM/etc driven web system.

either that, or create a batch system that creates a new user folder with certain priveledges, and then binds apache to that group of users. which seems bloated.

id be going with the database/scripted front end myself.

and quamen, i guess its just the luck of the draw. sometimes when i test long URLs from my home machine, i get a connection, and other times it backfires and tries to link me to machinename.local/directory.

ah, the interesting world of apache configs...

W2ttsy