小编atf*_*nes的帖子

Nginx反向代理Websocket身份验证 - HTTP 403

我正在使用Nginx作为Spring启动应用程序的反向代理.我还使用带有sockjs和stomp消息的Websockets.

这是上下文配置.

<websocket:message-broker application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/localization" >
        <websocket:sockjs/>
    </websocket:stomp-endpoint>
    <websocket:simple-broker prefix="/topic" />
</websocket:message-broker>
Run Code Online (Sandbox Code Playgroud)

这是客户端代码:

var socket = new SockJS(entryPointUrl);
var stompClient = Stomp.over(socket);

var _this = this;

stompClient.connect({}, function () {
    stompClient.subscribe('/app/some-url', function (message) {
         // do some stuff
    });
});
Run Code Online (Sandbox Code Playgroud)

我也是Spring Security来保护一些内容.

@Configuration
@Order(4)
public static class FrontendSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/js/**", "/css/**", "/webjars/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").permitAll()
                .and()
                .logout().permitAll();
    }

}
Run Code Online (Sandbox Code Playgroud)

当我在Nginx反向代理后面运行这个应用程序时,一切都很好.这是相反的配置:

    proxy_pass http://testsysten:8080;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host; …
Run Code Online (Sandbox Code Playgroud)

nginx spring-security websocket spring-boot

8
推荐指数
2
解决办法
9138
查看次数

在全局 npm install 上构建 Git 依赖

Npm 允许使用自定义 git URL 来指定依赖项(请参阅package.json 中的 npm install private github repositories by dependency)。

但是,这些依赖项通常打包并发布到 npm 注册表,因此可以按名称安装它们。这个发布过程通常包括构建文件、缩小文件等,这些文件通常在 github 中不可用。

使用自定义 git URL 安装依赖项时,可能需要这些构建、缩小等文件,但它们将不可用。

要生成这些文件,可以使用npm 脚本在安装生命周期中运行一个钩子。但是,我找不到适合此任务的脚本,因为:

  1. Prepublish不在全局安装中运行。它将被弃用,以支持prepareprepublishOnly
  2. Prepare也仅在本地安装上运行。(编辑: prepare 也可以在全局安装上运行,这与npm 脚本文档中所说的不同)
  3. Prepack安装 git 依赖项之前npm pack之后运行(如文档所述)。但是,在全局安装(节点 LTS 版本:v6.11.0,npm 版本(来自节点 LTS):3.10.10)中尝试此脚本时不会触发它。npm publish
  4. 最佳实践中不推荐预安装和安装

不要使用安装。使用 .gyp 文件进行编译,并为其他任何内容预发布。您几乎不必显式设置预安装或安装脚本。如果您正在这样做,请考虑是否还有其他选择。安装或预安装脚本的唯一有效用途是编译,必须在目标架构上完成。

  1. Postinstall也将在包的本地安装中运行,这不是预期的行为。

node.js npm

5
推荐指数
1
解决办法
933
查看次数

标签 统计

nginx ×1

node.js ×1

npm ×1

spring-boot ×1

spring-security ×1

websocket ×1