简体   繁体   中英

Run node.js and PHP/apache on same instance on AWS

I have installed the node js on Ec2 successfully and my website and domain are running fine but when I try to run node js it won't run.

I have follow the some tutorial and I have done the following step on my aws.

 1. I have added a port 9000 on my security group
 2. I have done the pre-routing on iptables using below command

    sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 9000

But after running above code my domain stop running means when I try to open my site mydomain.com it shows nothing and If I remove the that rule than again its working.

I have also tried the below solution to running node as root level to listen port on 80.

sudo node server.js

but after that I am getting below error

Error: listen EADDRINUSE :::80
    at Object.exports._errnoException (util.js:949:11)
    at exports._exceptionWithHostPort (util.js:972:20)
    at Server._listen2 (net.js:1253:14)
    at listen (net.js:1289:10)
    at Server.listen (net.js:1385:5)
    at Object.<anonymous> (/home/mcook/domains/development.mcook.co.in/public_html/server.js:36:5)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)

I just want to make my node and my site both must running and for that which command and port I need to run.

Following command forward all your traffic of PORT 80 to PORT 9000 .

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 9000

Why are you doing so? As You've already opened the PORT 9000 from AWS security groups so you can make your node.js to connect on PORT 9000 directly from the code.

The reason you see the blank page after executing above code is Your web server runs on PORT 80 and every request that is forwarded to node.js server on port 9000 which actually doesn't have anything to show.

So don't run above command simply run the node.js server on PORT 9000 and make connection to PORT 9000 only from client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM