问题
I'm trying to get a Yaws web server working on a cloud service (Amazon AWS). I've compilled and installed a local copy on the server. My problem is that I can't get Yaws to run while running on either port 8000 or port 80.
I have the following configuration in yaws.conf:
port = 8000 listen = 0.0.0.0 docroot = /home/ubuntu/yaws/www/test dir_listings = true
This produces the following successful launch/result:
Eshell V5.8.5 (abort with ^G)
=INFO REPORT==== 16-Sep-2012::17:21:06 === Yaws: Using config file /home/ubuntu/yaws.conf
=INFO REPORT==== 16-Sep-2012::17:21:06 === Ctlfile : /home/ubuntu/.yaws/yaws/default/CTL
=INFO REPORT==== 16-Sep-2012::17:21:06 === Yaws: Listening to 0.0.0.0:8000 for <3> virtual servers: - http://domU-12-31-39-0B-1A-F6:8000 under /home/ubuntu/yaws/www/trial -
=INFO REPORT==== 16-Sep-2012::17:21:06 === Yaws: Listening to 0.0.0.0:4443 for <1> virtual servers: -
When I try to access the the url (http://ec2-72-44-47-235.compute-1.amazonaws.com), it never connects. I've tried using paping to check if port 80 or 8000 is open(http://code.google.com/p/paping/) and I get a "Host can not be resolved" error, so obviously something isn't working.
I've also tried setting the yaws.conf so its at Port 80, appearing like this:
port = 8000 listen = 0.0.0.0 docroot = /home/ubuntu/yaws/www/test dir_listings = true
and I get the following error:
=ERROR REPORT==== 16-Sep-2012::17:24:47 === Yaws: Failed to listen 0.0.0.0:80 : {error,eacces}
=ERROR REPORT==== 16-Sep-2012::17:24:47 === Can't listen to socket: {error,eacces} =ERROR REPORT==== 16-Sep-2012::17:24:47 === Top proc died, terminate gserv =ERROR REPORT==== 16-Sep-2012::17:24:47 === Top proc died, terminate gserv =INFO REPORT==== 16-Sep-2012::17:24:47 === application: yaws exited: {shutdown,{yaws_app,start,[normal,[]]}} type: permanent {"Kernel pid terminated",application_controller," {application_start_failure,yaws,>>>>>>{shutdown,>{yaws_app,start,[normal,[]]}}}"}
I've also opened up the port 80 using iptables. Running sudo iptables -L gives this output:
Chain INPUT (policy ACCEPT) target prot opt source destination
ACCEPT tcp -- ip-192-168-2-0.ec2.internal ip-192-168-2-16.ec2.internal tcp dpt:http ACCEPT tcp -- 0.0.0.0 anywhere tcp dpt:http ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:httpChain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination
Thanks for the patience
回答1:
Actually, I found the answer to why I couldn't get it to work, through this forum post (http://www.trapexit.org/forum/viewtopic.php?p=42923).
It states:
2a. I run yaws on 8080 and have nginx reverse proxying
from http://mydomain:80 to 8080. Yaws won't run as a
low-privilege user if you want it to listen on port
80.
2b. nginx.conf needs the following directives:
server {
listen 80;
server_name yourdomain.com;
access_log /path/to/access/log.log
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}
}
Basically, I installed nginx, and configured it to run as a proxy server.
I have used the same solution in order to get a Chicago Boss framework to run, the only difference is that I have nginx proxy_pass set to >http://127.0.0:8001 since Chicago Boss runs on 8001 by default. Anyone know how this effects an erlang servers concurrency advantages if someone is using nginx as a proxy server, or it has no effect what so ever?
回答2:
One of the error reports you've pasted shows the reason why you cannot start the server on port 80: permissions ({error, eaccess}).
=ERROR REPORT==== 16-Sep-2012::17:24:47
=== Yaws: Failed to listen 0.0.0.0:80 : {error,eacces}
Regarding the launch on port 8000, did you try to SSH to the machine and connect to the server locally (e.g. via telnet)? If that works, your problem must be, as others suggested, related to either the Ubuntu firewall not having port 8000 open or the Security Group for your EC2 instance not containing a route which allows inbound traffic on that port.
Said that, this question should probably be moved to ServerFault or AskUbuntu.
回答3:
There are two things to look for:
- check your security group settings for your instance and make sure that the port 80 or 8000 is open (accessible from
0.0.0.0/32
). - try binding your server to the internal IP address of the machine. Some servers need to listen to this interface instead of
0.0.0.0.
You can find out your internal IP either in the console or withifconfig
回答4:
Its worth noting that the interactive command line requires root permissions:
sudo su
yaws -i --id whatever
You must also specify an ID if the yaws daemon is running at the same time.
回答5:
http://hyber.org/privbind.yaws
binding to privileged ports
A common misfeature found on UN*X operating systems is the restriction that only root can bind to ports below 1024. Many a dollar has been wasted on workarounds and -often- the results are security holes.
$ setcap 'cap_net_bind_service=+ep' /usr/lib/erlang/erts-5.7.4/bin/beam
回答6:
@Bernard is correct that the EC2 instance has a firewall protecting it. You need to modify the EC2 Security Group (You can find it on the left hand side in the management console web interface) for the instance to allow inbound TCP traffic to the port you want to use. For port 80 you can select HTTP
from the combo box. For port 8080, select Custom TCP Rule
and type in the port number.
来源:https://stackoverflow.com/questions/12449114/installing-yaws-server-on-ubuntu-12-04-using-a-cloud-service