1

I'm trying to serve a Node application through Nginx on my Mac, and I've run into a problem.

On Ubuntu, I always change the config file to this

server { listen 80; server_name example.com; location / { proxy_pass http://127.0.0.1:3000; 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; } } 

but when I do the same on my Mac, I get this error when I'm running the server:

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

Any suggestions on why this is happening would be appreciated.

5
  • What file is that you've edited, and how is it included into your nginx.conf file? Commented Feb 20, 2016 at 14:34
  • Is this the complete nginx.conf? On my nginx.conf it is prepended with a http-block. Commented Feb 20, 2016 at 14:38
  • @DaveWood I've configured the /usr/local/etc/nginx/nginx.conf. Commented Feb 20, 2016 at 14:39
  • @kometen Yes this is the complete conf file, it's what I use on my ubuntu servers. Commented Feb 20, 2016 at 14:39
  • @martin OK. Then I'll undelete my answer. I was a bit unshure. :-) Commented Feb 20, 2016 at 14:41

2 Answers 2

3

According to nginx's page http is the outer block. So it should work be adding a http block before the server block.

Sign up to request clarification or add additional context in comments.

Comments

0

By doing that i get host not found in "$PORT" of the "listen" directive

http { server { listen $PORT; server_name test-rpc.test.com; location / { proxy_ssl_server_name on; proxy_pass http://test-rpc; } } upstream test-rpc { server localhost:2000 max_fails=3 fail_timeout=10s; server localhost:2001 max_fails=3 fail_timeout=10s; } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.