skip to Main Content

I have a nodejs backend hosted on AWS EC2 Ubuntu 20.04 instances.

When i ssh into my server, everything is working accordingly. Today i tried configuring nginx, so i created website.com files inside sites-available .

website.com

server {
        listen 80;
        listen [::]:80;

         root /home/ubuntu/apps/yelp-app/client/build;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name api.website.com www.api.website.com;

        location / {
                try_files $uri /index.html;
        }

         location /api {
            proxy_pass http://localhost:3001;
            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;
        }

}

After saving that file, i ran the following command:

sudo ln -s /etc/nginx/sites-available/website.com /etc/nginx/sites-enabled/

From the docs, in order to enable the new site i need to restart nginx using the following:

systemctl restart nginx

Unfortunately, it keeps asking for the ubuntu user password which i did not ever set.

Can someone help me out?

When i run journalctl -xe -u nginx this is what i get:


-- Subject: A start job for unit nginx.service has begun execution
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit nginx.service has begun execution.
-- 
-- The job identifier is 23231.
Jan 11 12:44:45 ip-172-31-40-105 nginx[164236]: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in >
Jan 11 12:44:45 ip-172-31-40-105 nginx[164236]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jan 11 12:44:45 ip-172-31-40-105 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FA>
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- An ExecStartPre= process belonging to unit nginx.service has exited.
-- 
-- The process' exit code is 'exited' and its exit status is 1.
Jan 11 12:44:45 ip-172-31-40-105 systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Jan 11 12:44:45 ip-172-31-40-105 systemd[1]: Failed to start A high performance web server and a reverse pro>
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit nginx.service has finished with a failure.
-- 
-- The job identifier is 23231 and the job result is failed.

2

Answers


  1. Chosen as BEST ANSWER

    This solution provided by Mehmet works but if you require not to change user use the following:

    sudo service nginx restart
    

  2. First be root then restart it.

    sudo su 
    systemctl restart nginx
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search