我的开发人员已将 Google、Twitter 等第三方身份验证添加到我们的网站。我现在想接手开发。我需要做的第一件事是能够在 localhost 中测试这些第三方身份验证。他给了我以下配置文件。
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";
}
}
然后我把它放到/usr/local/etc/nginx/nginx.conf
我的 MacOS 下。但是,我无法成功运行 nginx:
$ 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
有谁知道如何解决这一问题?
编辑1:
我尝试使用nginx 的默认配置,但brew services restart nginx
随后brew services list
仍然显示错误。
答案1
您的同事提供的配置片段应该位于http
块内。
但是,当您将其放入nginx.conf
并用作 nginx 配置时,它不起作用,因为http
缺少级别。
nginx 通常附带一个nginx.conf
文件,该文件具有良好的默认值,然后include
在其内部http
部分包含其他配置。
您需要检查nginx.conf
随 nginx 安装一起提供的内容,并查看它如何包含其他配置文件。
答案2
看来brew services start nginx
,,在这里并不可靠brew services list
。brew services stop nginx
相比之下,sudo nginx
(启动 nginx)sudo nginx -s stop
对我来说是有用的。