summary: [通过Nginx实现NCC的https访问,并解决UClient应用的问题]
通过Nginx 安装配置反向代理,实现NC、NCC的https访问。
本文以NCC2005为例,说明如何配置Nginx、NCC,以及解决UClient无法访问https代理的问题。
其他版本的NC可以以此类推。
NCC2005应用地址:http://10.16.51.147:2005
Nginx_1.22.0服务地址:10.16.51.147
最终实现代理访问:
https://10.16.51.147->http://10.16.51.147:2005
https://10.16.51.147:4433->http://10.16.51.147:2005
http://10.16.51.147->http://10.16.51.147:2005
nginx.conf文件配置如下:
# Generated by nginxconfig.io
# See nginxconfig.txt for the configuration share link
user root;
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
# Load modules
include /usr/local/nginx/conf/modules-enabled/*.conf;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
types_hash_bucket_size 64;
client_max_body_size 2048M;
# MIME
include mime.types;
default_type application/octet-stream;
# Logging
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log;
error_log logs/error.log warn;
# SSL
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
# Diffie-Hellman parameter for DHE ciphersuites
# ssl_dhparam /usr/local/nginx/conf/dhparam.pem;
# Mozilla Old configuration
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA;
ssl_prefer_server_ciphers on;
# OCSP Stapling
# ssl_stapling on;
# ssl_stapling_verify on;
# resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
# resolver_timeout 2s;
# ssl_trusted_certificate /usr/local/nginx/conf/ssl/ncc2005.cxjk.com.crt;
# Connection header for WebSocket reverse proxy
# map $http_upgrade $connection_upgrade {
# default upgrade;
# "" close;
# }
# map $remote_addr $proxy_forwarded_elem {
# # IPv4 addresses can be sent as-is
# ~^[0-9.]+$ "for=$remote_addr";
# # IPv6 addresses need to be bracketed and quoted
# ~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\"";
# # Unix domain socket names cannot be represented in RFC 7239 syntax
# default "for=unknown";
# }
# map $http_forwarded $proxy_add_forwarded {
# # If the incoming Forwarded header is syntactically valid, append to it
# "~^(,[ \\t]*)*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*([ \\t]*,([ \\t]*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem";
# # Otherwise, replace it
# default "$proxy_forwarded_elem";
# }
# Load configs
include /usr/local/nginx/conf/conf.d/*.conf;
# ncc2005.cxjk.com
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name 10.16.51.147;
# SSL
ssl_certificate /usr/local/nginx/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/ssl/server.key;
# security headers
# add_header X-XSS-Protection "1; mode=block" always;
# add_header X-Content-Type-Options "nosniff" always;
# add_header Referrer-Policy "no-referrer-when-downgrade" always;
# add_header Content-Security-Policy "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always;
# add_header Permissions-Policy "interest-cohort=()" always;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
# . files
location ~ /\.(?!well-known) {
deny all;
}
# logging
access_log logs/ncc2005.cxjk.com.access.log;
error_log logs/ncc2005.cxjk.com.error.log warn;
# reverse proxy
location / {
proxy_pass http://10.16.51.147:2005;
proxy_set_header Host $http_host; # ncc必须设置
proxy_http_version 1.1; # 定义用于代理的HTTP协议版本,默认情况下将其设置为1.0。对于Websocket和 keepalive 连接,需要使用1.1版
# proxy_cache_bypass $http_upgrade; # 设置不从缓存中获取响应的条件
# Proxy SSL
proxy_ssl_server_name on;
# Proxy headers
# 如果应用程序使用Websockets,则这些Upgrade、Connection字段是必填字段
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr; # 将真实的访客远程IP地址转发到代理服务器
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # ncc必须设置(包含客户端被代理的每个服务器的IP地址的列表)
# proxy_set_header X-Forwarded-Proto $scheme; # ncc不可设置此参数(在HTTPS服务器块中使用时,来自代理服务器的每个HTTP响应都会重写为HTTPS)
proxy_set_header X-Forwarded-Host $host; # 定义客户端请求的原始主机
proxy_set_header X-Forwarded-Port $server_port; # 定义客户端请求的原始端口
# Proxy timeouts 超时设置不宜过短,否则类似导入数据这样的长业务场景会发生upstream time out错误
proxy_connect_timeout 7200s;
proxy_send_timeout 7200s;
proxy_read_timeout 7200s;
proxy_redirect http:// $scheme://; # ncc必须设置,否则轻量端访问异常(将后端响应header location内容中的http://替换成用户端协议https://)。如果做了http强转https,且都是采用默认端口(80,443),则可不设置此参数,因为重定向后的http:80会转为https:443。
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
}
# favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
}
# robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
gzip_min_length 10k;
gzip_disable "MSIE [1-6]\.";
}
# 4433 端口
server {
listen 4433 ssl;
listen [::]:4433 ssl;
server_name 10.16.51.147;
# SSL
ssl_certificate /usr/local/nginx/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/ssl/server.key;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
# . files
location ~ /\.(?!well-known) {
deny all;
}
# logging
access_log logs/ncc2005.cxjk.com.access.log;
error_log logs/ncc2005.cxjk.com.error.log warn;
# reverse proxy
location / {
proxy_pass http://10.16.51.147:2005;
proxy_set_header Host $http_host; # ncc必须设置
proxy_http_version 1.1; # 定义用于代理的HTTP协议版本,默认情况下将其设置为1.0。对于Websocket和 keepalive 连接,需要使用1.1版
# Proxy SSL
proxy_ssl_server_name on;
# Proxy headers
proxy_set_header X-Real-IP $remote_addr; # 将真实的访客远程IP地址转发到代理服务器
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # ncc必须设置(包含客户端被代理的每个服务器的IP地址的列表)
proxy_set_header X-Forwarded-Host $host; # 定义客户端请求的原始主机
proxy_set_header X-Forwarded-Port $server_port; # 定义客户端请求的原始端口
# Proxy timeouts 超时设置不宜过短,否则类似导入数据这样的长业务场景会发生upstream time out错误
proxy_connect_timeout 7200s;
proxy_send_timeout 7200s;
proxy_read_timeout 7200s;
proxy_redirect http:// $scheme://; # ncc必须设置,否则轻量端访问异常(将后端响应header location内容中的http://替换成用户端协议https://)
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
}
# favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
}
# robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
gzip_min_length 10k;
gzip_disable "MSIE [1-6]\.";
}
# HTTP redirect http转为https
server {
listen 80;
listen [::]:80;
server_name 10.16.51.147;
# 两种方式均可
return 301 https://10.16.51.147$request_uri;
# rewrite ^(.*) https://10.16.51.147$1 permanent;
}
}
完成Nginx配置后,轻量端就可以访问了。如果还需要使用UClient访问轻量端及重量端,则需要执行以下步骤:
配置文件
配置https应用,在以下文件中加入参数设置:scheme=https (该参数不为空时,优先使用该参数设置的协议,否则使用UClient传入的protocol)
轻量端https协议配置:ncchome\hotwebs\nccloud\WEB-INF\config\uclient_appconfig.properties
重量端https协议配置:ncchome\webapps\nc_web\Client\uclient_appconfig.properties
https://10.16.51.147/nccloud可以正常访问,而非443端口https://10.16.51.147:4433/nccloud无法访问,需要在Nginx中加入配置proxy_redirect http:// $scheme://;
因为当前版本的UClient在搜索下载应用时,会将https协议变更为http,导致无法正确下载应用。该问题需要通过上述的补丁解决。
相关问题具体表现如下:
搜索https://10.16.51.147,下载的重量端应用为http://host:80,点击无法方法应用。
搜索https://10.16.51.147,下载的轻量端应用为http://host:80/nccloud,点击无法访问
搜索https://10.16.51.147:4433,无法下载重量端,无法下载轻量端
通过https://10.16.51.147 下载的轻量端应用实际访问地址是http://host:80/nccloud,Nginx已经做了强转,但是点击应用后提示页面错误,无法访问URLhttps://10.16.51.147/nccloud,
再次点击该URL,则可正常进入系统。
该问题需要UClient修复。
手工修改轻量端应用的app.esc下载地址为https://10.16.51.147:4433/nccloud,安装轻量应用,点击应用访问地址栏访问的是http://10.16.51.147:4433/nccloud,页面提示400错误:The plain HTTP request was sent to HTTPS por。
问题现象及方案同问题1。
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po