【问题标题】:nginx configuration to apache httpd confnginx 配置到 apache httpd conf
【发布时间】:2022-01-29 14:31:57
【问题描述】:

我想将此配置 sn-p 转换为 apache。不明白位置/添加标题标签将被转换成什么

location / {
    root   html;
    index  index.html index.htm;
    # Security based headers
    add_header Content-Security-Policy "frame-ancestors 'self'";
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-XSS-Protection "1; mode=block";
}

# reverse proxy for xyz
location /zyz/v1 {
    proxy_pass         https://localhost:4855/zyz/v1;
}

【问题讨论】:

标签: apache nginx webserver nginx-reverse-proxy


【解决方案1】:

给你,这是你需要添加到 apache2.conf/httpd.conf 的 Apache 配置,而不是 .htaccess。

Header set Content-Security-Policy "frame-ancestors 'self'"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header set X-Content-Type-Options nosniff
Header set X-Frame-Options SAMEORIGIN
Headet set X-XSS-Protection "1; mode=block"

RewriteEngine On
RewriteRule ^/zyz/v1(/|$) https://localhost:4885/xyz/v1 [P,L]
# OR
#ProxyPass /zyz/v1 https://localhost:4885/xyz/v1

Header 需要启用 mod_headers。

Rewrite* 需要启用 mod_rewrite。

另外,对于Rewrite*,当您在<VirtualHost> 部分之外添加时,您需要将RewriteEngine On 添加到所有虚拟主机,并在this @987654329 下面添加RewriteOptions InheritDown @。

如果您还想将查询字符串传递给后端服务器,请将 [P,L] 更改为 [P,QSA,L]。您需要为[P] 启用mod_proxy。我相信您还想启用mod_proxy_http,因为您希望 apache 使用 HTTP 与后端服务器通信。

【讨论】:

  • 感谢详细答案以及模块名称。我理解的第一部分。但是对于 #xyz 位置的反向代理 /zyz/v1 { proxy_pass localhost:4855/zyz/v1; } 不应该转换成Proxypass /zyz/v1 https://localhost:4885/xyz/v1
  • @MadhusudanSamantray,也很好。它的ProxyPass 不是Proxypass,我敢肯定
  • 感谢您的确认。它是 ProxyPass 。注意到
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-03
  • 2016-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-14
  • 1970-01-01
相关资源
最近更新 更多