Cannot start a ngnix [closed]

My developer has added third-party authentications like Google, Twitter to our website. I would like to take over the development now. The first thing I need to do is to be able to test these third-party authentications in localhost. He gave me the following configuration file.

upstream mywebsite {
   server 178.62.00.00:443;
}

server {
    listen              443 ssl;
    server_name localhost;
    ssl_certificate /etc/ssl/localhost/localhost.crt;
    ssl_certificate_key /etc/ssl/localhost/localhost.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_session_timeout 1d;
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;
    add_header X-Frame-Options "";
    proxy_ssl_name "www.mywebsite.io";
    proxy_ssl_server_name on;

    location ~ /socialLoginSuccess {
        rewrite ^ '/#/socialLoginSuccess' redirect;
    }

    location ~ /auth/(.*) {
        proxy_pass  https://mywebsite/myapp/auth/$1?$query_string;
        proxy_set_header Host localhost;
    }

    location / {
        proxy_set_header    Host                $host;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto   $scheme;
        proxy_set_header    Accept-Encoding     "";
        proxy_set_header    Proxy               "";
        proxy_pass          http://localhost:3000/;

        # These three lines added as per https://github.com/socketio/socket.io/issues/1942 to remove socketio error
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
    }
}

I then put it as /usr/local/etc/nginx/nginx.conf under my MacOS. However, I could not run nginx successfully:

$ nginx -t
nginx: [emerg] "upstream" directive is not allowed here in /usr/local/etc/nginx/nginx.conf:1
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

$ brew services start nginx
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

$ brew services list
Warning: Calling bottle :unneeded is deprecated! There is no replacement.
Please report this issue to the stripe/stripe-cli tap (not Homebrew/brew or Homebrew/core):
  /usr/local/Homebrew/Library/Taps/stripe/homebrew-stripe-cli/stripe.rb:9

256
Name                  Status  User     Plist
[email protected] stopped          
nginx                 error   softtimur /usr/local/opt/nginx/homebrew.mxcl.nginx.plist

Does anyone know how to fix this?

Edit 1:

I tried to use the default configuration of nginx, but brew services restart nginx followed by brew services list still showed error.


The configuration snippet given by your colleague should reside inside http block.

However, when you put that into nginx.conf and use that as a nginx configuration, it doesn't work because the http level is missing.

nginx often ships with a nginx.conf file, which has good defaults, and then include inside the http section to include other configuration.

You need to check the nginx.conf shipped with your nginx install, and see how it includes other config files.