Thursday, September 8, 2022

AWS EC2 Amazon Linux nginx: [emerg] unknown directive "stream"

 Creating a reverse proxy for servers in restricted mode using NGINX in AWS EC2 Amazon Linux 2 can be frustrating. The following error is one of those quirks:

[root@ip-10-219-0-153 nginx]# nginx -t

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:9

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


Here is the quick easy solution: Just install  nginx-mod-stream and  you should be fine.

[root@ip-10-219-0-153 nginx]# yum install nginx-mod-stream

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd

amzn2-core                                                                                 | 3.7 kB  00:00:00

Resolving Dependencies

--> Running transaction check

---> Package nginx-mod-stream.x86_64 1:1.20.0-2.amzn2.0.5 will be installed

--> Finished Dependency Resolution

Dependencies Resolved


 Package                     Arch              Version                         Repository                    Size



 nginx-mod-stream            x86_64            1:1.20.0-2.amzn2.0.5            amzn2extra-nginx1             87 k

Transaction Summary


Install  1 Package

Total download size: 87 k

Installed size: 172 k

Is this ok [y/d/N]: y

Downloading packages:

nginx-mod-stream-1.20.0-2.amzn2.0.5.x86_64.rpm                                             |  87 kB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : 1:nginx-mod-stream-1.20.0-2.amzn2.0.5.x86_64                                                   1/1

  Verifying  : 1:nginx-mod-stream-1.20.0-2.amzn2.0.5.x86_64                                                   1/1


  nginx-mod-stream.x86_64 1:1.20.0-2.amzn2.0.5


[root@ip-10-219-0-153 nginx]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

Hope that helps.

No comments: