0

I am having issues restarting nginx restart. I'm very new to ubuntu and nginix. I am trying to change the configuration of nginx.conf and default.conf(newly created). My main goal is to deploy my MERN app to Amazon Ec2

Here is my configuration respectively

server {
    #listen       80;
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name  yourdomain.com;

    access_log /home/ubuntu/client/server_logs/host.access.log main;

    location / {
        root   /home/ubuntu/client/deploy;
        index  index.html index.htm;
        try_files $uri /index.html;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    server_tokens off;

    location ~ /\.ht {
        deny  all;
    }

}

user ubuntu;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;

    client_body_buffer_size 100k;
    client_header_buffer_size 1k;
    client_max_body_size 100k;
    large_client_header_buffers 2 1k;
    client_body_timeout 10;
    client_header_timeout 10;
    keepalive_timeout 5 5;
    send_timeout 10;
    server_tokens off;
    #gzip  on; on;

    include /etc/nginx/conf.d/*.conf;
}

if i try to restart nginx i with the following command "sudo service nginx restart" get the following error:

Job for nginx.service failed because the control process exited with an error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

I really need someone to tell me what am doing wrong because of my little experience with ubuntu and nginx. or is there any link i can access that will be helpful in understanding nginx configurations. Any help will be appreciated

out put from systemctl status nginx.service and journalctl -xe":

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2020-11-21 12:23:42 UTC; 22s ago
       Docs: man:nginx(8)
    Process: 21094 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: [emerg] unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
The job identifier is 5626.
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: [emerg] unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd

I also checked the error log with "cat /var/log/nginx/error.log" and i got the following :

ubuntu@ip-172-31-23-90:~$ cat /var/log/nginx/error.log
2020/11/21 07:47:49 [emerg] 18846#18846: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 07:54:57 [emerg] 18898#18898: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 07:59:37 [emerg] 18924#18924: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 11:09:41 [emerg] 20449#20449: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 11:20:03 [emerg] 20485#20485: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 11:52:44 [emerg] 20822#20822: unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
2020/11/21 12:23:42 [emerg] 21094#21094: unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
3
  • What are the output of the suggested commande ystemctl status nginx.service and journalctl -xe ? – Soren A Nov 21 '20 at 12:21
  • Your configuration creates a file at /var/log/nginx/error.log. Does it contain anything useful? – Richard Smith Nov 21 '20 at 12:22
  • @Soren I have updated my question to include some of the output – workfily app Nov 21 '20 at 12:29
1

Your error is already there in the output you have posted:

Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: [emerg] unknown directive "sten" in /etc/nginx/conf.d/default.conf:1

So investigate the file /etc/nginx/conf.d/default.conf and make the necessary corrections. There is no sten directive, there is listen directive of course :)

Instead of restarting NGINX every time, have a habit of reloading it (if it is already running anyway). This will ensure better uptime, in case the configuration has errors.

sudo systemctl reload nginx

To check configuration issues in terminal, run:

nginx -t

To dump complete NGINX configuration to terminal (with includes), use:

nginx -T

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.