Error while running nginx


#1

Hello, I am running Edx instance on Azure VM. I have attached the DNS to my edx instance. I want to get ssl certificate. So I was trying to get this.

  1. First I added fully qualified Domain name in LMS configuration file. as www.mydomain.com
  2. Then I ran First 5 commands properly then,
  3. Then I run cmd: sudo certbot --authenticator standalone --installer nginx --pre-hook “service nginx stop” --post-hook “service nginx start”

But I got error as

Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: [emerg] unknown directive “www.mydomain.com” in /etc/nginx/sites-enabled/lms:12

nginx: configuration file /etc/nginx/nginx.conf test failed

It also shows : The nginx plugin is not working; there may be problems with your existing configuration.

The error was: MisconfigurationError(‘Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] unknown directive “www.millionlightsdev.com” in /etc/nginx/sites-enabled/lms:12\nnginx: configuration file /etc/nginx/nginx.conf test failed\n’,)

There seems to be problem with nginx server. Please guide me to install my ssl certification


#2

Hi,

Can you share us your config file at /etc/nginx/sites-enabled/lms ? (Upload it to a pastebin or gist would be best)

Thank you


#3

Hello Friend,

Please find the pastebin URL which has my LMS config file.

http://dpaste.com/1JJZSTC

Please suggest me the solution.


#4

Hi,

You would need server_name before the domain name for Nginx to work.

server {
  # LMS configuration file for nginx, templated by ansible
  server_name www.millionlightsdev.com   #This is my domain

Thank you


#5

Okay Thanks Stevenzhu.
So Do I need to add my Azure VM name there in place of Server_name?


#6

Nope…

Just add the server_name before your domain.

(Consider this definition for server_name

Server names are defined using the server_name directive and determine which server block is used for a given request. See also “How nginx processes a request”. They may be defined using exact names, wildcard names, or regular expressions:

From nginx.org
http://nginx.org/en/docs/http/server_names.html

In short & my opinion, server_name specify the domain this Nginx server would respond to request. You can’t just copy and paste your domain name in the vHost without server_name directive )


#7

Many Thanks Stevenzhu…


#8

Hi, I got the certificate and all. But just one query: In my LMS file, there is no line like this:
#listen 80;

(Anyways it is to be commented/deleted)
But there are two lines below as:

listen 80 default_server;
return 404; # managed by Certbot

What Do I have to do with these lines?


#9

Hi,

I don’t really understand why there’s an return 404… However, if you only have one vHosts, the default_server doesn’t quite matters.

(It means if theer are other domains not registered on vHost, the server is going to display this domain…)

The default server also going to be use in sni settings. (The default server will always be the major / main certificate served)

Thank you


#10

Thanks buddy.

Now there is problem with my nginx. Although nginx is installed. When I run: sudo systemctl restart nginx
It says:

mlopenedx@MillionEdx:~$ sudo systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.


#11

Okay…

Check the two commands:

  1. systemctl status Nginx -l
  2. nginx -t

And see what’s the output…

Then you can probably figure out the error :slight_smile:


#12

Hi, Below is output.

mlopenedx@MillionEdx:~$ systemctl status Nginx -l
● Nginx.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
mlopenedx@MillionEdx:~$

Why is it saying nginx Not-Found. Do I need to re install or update nginx. What is this problem. Please guide me. Appreciate your help.

mlopenedx@MillionEdx:~$ sudo nginx -t
nginx: [warn] server name “/server/server-error.html” has suspicious symbols in /etc/nginx/sites-enabled/lms:17
nginx: [warn] server name “/server/server-error.html” has suspicious symbols in /etc/nginx/sites-enabled/lms:233
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
mlopenedx@MillionEdx:~$

Also when I see LMS17 & 233 the line in LMS It is:

error_page 504 /server/server-error.html;


#13

Okay…

I’m just curious…

On server name (the LMS vHost ), do you put a ; after the domain?

Should be server_name www.millionlightsdev.com;

Thank you


#14

Unix environments are always case-sensitive, distinguishing between capital letters and lower-case letters. Most software and directory names in a Unix environment are conventionally written in lower-case.

If you literally wrote systemctl status Nginx then you were referring to a nonexistent Nginx service which is different from the nginx service.

Even software that is written with a brand name with a capital letter, such as Certbot, is most often installed and referred to in lower-case in command lines, like certbot renew.


#15

Hello schoen,
Thanks. But now I am not able to browse LMS on my IP address. It is giving error:
404 Not Found nginx
I saw error log file from : /var/log/nginx/error.log
It is as below:

2018/06/13 15:56:20 [emerg] 2394#2394: unknown directive "www.millionlightsdev.com" in /etc/nginx/sites-enabled/lms:12
2018/06/13 16:29:09 [warn] 34521#34521: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:13
2018/06/13 16:30:25 [warn] 35298#35298: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:13
2018/06/13 16:30:25 [notice] 35298#35298: signal process started
2018/06/13 16:30:25 [error] 35298#35298: invalid PID number "" in "/var/run/nginx.pid"
2018/06/13 16:30:25 [warn] 35299#35299: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:13
2018/06/13 16:31:24 [warn] 36056#36056: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:13
2018/06/13 16:31:24 [warn] 36056#36056: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:226
2018/06/13 16:31:24 [notice] 36056#36056: signal process started
2018/06/13 17:21:30 [warn] 73552#73552: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:17
2018/06/13 17:21:30 [warn] 73552#73552: server name "/server/server-error.html" has suspicious symbols in /etc/nginx/sites-enabled/lms:233
2018/06/13 17:21:30 [emerg] 73552#73552: bind() to 0.0.0.0:18100 failed (98: Address already in use)

Can you help me solve the error?


#16

Please post the contents of the file /etc/nginx/sites-enabled/lms here again. It’s clear that it contains some kind of formatting error.


#17

Hello schoen, please find below LMS file Content:

http://dpaste.com/0F9QB5N

And advise me.


#18

You are missing the semicolon character ; at the end of line 13.

http://dpaste.com/0F9QB5N#line-13


#19

This is the same problem that @stevenzhu noted above

Error while running nginx

but it seems that you haven’t fixed it yet.


#20

Okay That is because in document there is no semi colon.
I will try now. Thanks.