I am trying to deploy a node js application on GoDaddy VPS hosting.
I have uploaded all the files to the server and started the server using pm2
following This Tutorial
My server is running on port 3021
which I want to run on port 80
for a particular domain.
I have completed steps till pm2
in the tutorial but from Nginx part, I cannot understand what to do next.
I have installed Nginx then running this command sudo vi /etc/nginx/sites-available/default
and adding configurations and when I am saving it an error shows [ Error writing /etc/nginx/sites-available/default: No such file or directory ]
I am running apache in the server. Is it possible to do the same using apache??
Edit
Here is my nginx config::
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
2
Answers
Try to use
/etc/nginx/conf.d/default.conf
instead of/etc/nginx/sites-available/default
to add your configuration. According to your config it should be the correct path to configure your server.If you want to use
/etc/nginx/sites-available/default
you should addinclude /etc/nginx/sites-available/*;
to your nginx.conf.So if you have
pm2
running then you are half way through 🙂 About nginx conf. This command:sudo vi /etc/nginx/sites-available/default
probably does not work because thesites-available
directory does not exist. Keep in mind thatsites-available
andsites-enabled
are not required by nginx. It’s just a good practice to have each server config in a separate file. But nginx will work without them too. If you are not planning to add any more servers, just use the/etc/nginx/nginx.conf
file to configure your server. What you need to do is to create a new server block with desired configuration, e.x:Just place the above config into
/etc/nginx/nginx.conf
insidehttp
block.Now check your nginx config:
If it’s successful, your nginx config is done.
It’s not over yet. One more thing to do- open port 80 in the firewall, like so:
You can check if it’s open:
Open your browser at
http://yourapp.com/
and see if it works.Remember to keep an eye on nginx and your app’s logs:
Hope it helps. Do not hesitate to share more info if you encounter any more problems