Reputation: 1970
I started PM2 and then when i do run the nginx start command. PM 2 started with no issue, but when i start NGINX. I always got this error.
nginx[26370]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) This is my config file
server {
listen 80 default_server;
listen [::]:80 ipv6only=on;
# SSL configuration
#
listen 443 ssl;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
#root /var/www/html;
root /root/my-website;
#app.js;
index index.html index.htm index.nginx-debian.html app.js;
server_name mywebsite.com;
ssl_certificate /root/folder/mywebsite.com.chained.crt;
ssl_certificate_key /root/folder/mywebsite.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://localhost:80;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
Upvotes: 0
Views: 984
Reputation: 377
Nginx's default working port is 80, just like any other web server. The port used by the node app should not be 80. You can choose suitable port values from 3000 to 50000. My suggestion is 8080.
After that, start your node app with pm2 and then change the proxy_pass section in the nginx configuration.
proxy_pass http://localhost:<new_app_port>;
Also, I wouldn't recommend using proxy_pass this way. You would be better off using this by defining an upstrean. You can scale your load balancing and multi-machine application under one address.
Nginx upstream config ref: http://nginx.org/en/docs/http/load_balancing.html
Upvotes: 2