iT邦幫忙

0

關於Linux Nginx config配置(自行完成,已結案)

  • 分享至 

  • twitterImage

直接進入正題 ...

1 name="wss300"
2
3 upstream $name  {
4
5 server 127.0.0.1:8080; #CB
6 }

小弟需要在 nginx.conf裡面配置一些宣告,但是會報錯

nginx: [emerg] unknown directive "name="wss300"" in /etc/nginx/conf.d/scott/scott.com/CB-scott-ws.conf:3

過程:

有事先做bash去測試執行狀況

#!/bin/bash

name="wss300"

name2="upstream $name"

echo $name2

執行結果也很正確

upstream wss300

但是代入到 nginx.conf裡面似乎就不能這樣使用了
已經Google過了,不曉得有沒有什麼特別的解法

備註:

set $cors ""; 的方法也試過了

set $cors ""; 需要包在 Server裡面
但是upstream又不能包在 Server裡面

而且set $name "wss300"; 透過bash去執行,只會得到空值


12:11 更新

目前使用的方式是 upstream 手 key

upstream wss300 {
server 127.0.0.1:8080; #CB
}

然後

Server {
....
....
....
set $name "wss300";
....
....
....
}
proxy_pass http://$name;

備註:proxy_pass http://$name; 的部分 是打算從外面抓進來用

froce iT邦大師 1 級 ‧ 2019-08-08 15:06:41 檢舉
像下面說的用lua-nginx-module吧,要用script的話就是sed去改conf然後restart service
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
dragonH
iT邦超人 5 級 ‧ 2019-08-08 14:36:47

查了很多文章

很多都是說要用 lua-nginx-module

去帶入 environment variable

實測

#myTarget=http://127.0.0.1:8081
env myTarget;

...

location / {
    set_by_lua $myTarget 'return os.getenv("myTarget")';
    proxy_pass $myTarget;
}

不知道是不是你要的

踏雪尋梅 iT邦研究生 5 級 ‧ 2019-08-09 09:13:21 檢舉

我後來改用比較笨的方法解決了 @@

upstream wss300 {

    server 127.0.0.1:8080;
}




server {

          # 啟用 SSL 服務
        listen 8080  ssl http2;
        ssl on;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
        # 設定 SSL 憑證
        ssl_certificate /etc/letsencrypt/live/scott.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/scott.com/privkey.pem;


 server_name
                wss1.scott.com;

set $name "wss300";


include nginxconfig.io/scott/scott-Cors.conf;

}

然後scott-Cors.conf;

proxy_pass http://$name;

這樣解決

我要發表回答

立即登入回答