cppcms 如何nginx 隐藏端口号

cppcms application的了解
编辑:www.fx114.net
本篇文章主要介绍了"cppcms application的了解",主要涉及到cppcms application的了解方面的内容,对于cppcms application的了解感兴趣的同学可以参考一下。
cppcms application的了解cppcms application的理解最近因为网站要支持nginx的动态负载均衡,因此要去掉cppcms内置的session机制。就顺便研究了一下cppcms的application。准确的讲,研究的是application类的子类的生命周期. 按照cppcms的规则,我们必须自己从application继承出自己的类,比如MyApp, 逻辑上,这个类的对象会被缓存到application pool中,代表了一个应用程序。cppcms的设计支持多个application运行在一起,也就是通过http://domain:port/(具有相同的domain和端口)能够访问到多个web apps。想法很大,不过我用不着多个应用在一个进程里面运行,真要是有多个应用,我肯定会放在不同的进程里面使用,进程隔离,会比较安全。防止一个web app写得不好,crash导致其他app也完蛋。 虽然多个application运行在不同的进程,意味着监听了各自的端口,访问的时候可能URI不一致,不过前面加上Nginx就可以将之统一起来。既然MyApp代表一个web application,因此它的对象就只能有一个,构造函数也只能被调用一次,默认情况下,经过测试,是在第一次web请求到达的时候被创建出来的。MyApp可以改写继承來自application的虚函数init,这个函数当每次web请求到来都会被调用。注意1.如果有全局的数据,现在可以放在MyApp里面作为成员变量. 不过如果涉及到既读又写的话,还是应该使用线程同步操作保证多线程安全。2.为了打造一个stateless的restful web app, 不要将session等数据保存在MyApp的成员变量中。可以写到真正的session server中,或者简化起见,直接写到mongodb中。以后每次再通过key读出来。key存放在客户端的cookie中,当用户登录验证通过后,可以通过调用继承自application::response().set_cookie 函数来将自己生成的key保存在cookie中,然后返回到浏览器端,浏览器可以将cookie保存起来。请看例子代码: cookie c(&my_session&, user-&oid, 36000, &/&);
response().set_cookie(c);多线程模型还未深究,目前只知道cppcms内部使用了线程池。
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:下次自动登录
现在的位置:
& 综合 & 正文
CentOS下CPPCMS的编译指南
1.下载最新版本的cppcms
svn co https://cppcms.svn.sourceforge.net/svnroot/cppcms/framework/trunk
tar -xjf cppcms_boost.tar.bz2
3.创建build目录
1.mkdir build
2.cd build
4.cmake -DCMAKE_INSTALL_PREFIX=/usr/ ..
安装到/usr/目录下 ,提示如下错误:
[...ocalhost build]$ cmake -DCMAKE_INSTALL_PREFIX=/usr/ ..
-- Looking for ICU libraries
-- ICU not found, disabling ICU localization backend
GNU Gcrypt or OpenSSL librarys are not found, disabling aes_encryptor
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
linked by target "booster" in directory /home/ryanliang/MySrc/cppcms/cppcms-0.99.4/booster
linked by target "booster-static" in directory /home/ryanliang/MySrc/cppcms/cppcms-0.99.4/booster
ZLIB_INCLUDE_DIR
used as include directory in directory /home/ryanliang/MySrc/cppcms/cppcms-0.99.4
-- Configuring incomplete, errors occurred!
在网上找到一个兄弟遇到了同样的问题():
他found the answer here:
通过输入如下命令,问题解决:
sudo apt-get install build-essential libpcre3-dev libicu-dev libgcrypt11-dev zlib1g-dev cmake
但是apt-get以及后面几个安装库都是debian或ubantu系统下才有的,我用的是CentOS,无法用;
解决思路:
1, 同样是找不到几个系统库,如果能够在centos下找到与那几个库类似的lib安装或许可行;
2,通过强大的grep依次找到,安装如下几个软件后,编译通过;
rpm -ivh rpm-build-4.4.2.3-22.el5.x86_64.rpm
sudo rpm -ivh rpm-build-4.4.2.3-22.el5.x86_64.rpm
sudo rpm -ivh pcre-devel-6.6-6.el5.x86_64.rpm
sudo rpm libicu-devel-3.6-5.16.x86_64.rpm
sudo rpm -ivh libicu-devel-3.6-5.16.x86_64.rpm
sudo rpm -ivh libgpg-error-devel-1.4-2.x86_64.rpm
sudo rpm -ivh libgcrypt-devel-1.4.4-5.el5.x86_64.rpm
sudo rpm -ivh zlib-devel-1.2.3-3.x86_64.rpm
sudo rpm -ivh zlib-1.2.3-3.x86_64.rpm
编译后的结果如下:
[ryanliang@localhost build]$ cmake -DCMAKE_INSTALL_PREFIX=/usr/ ..
-- Looking for ICU libraries
-- ICU Found, building booster locale
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wuliang/MySrc/cppcms-0.99.10.1/build
[ryanliang@localhost build]$ make test
Running tests...
Start processing tests
Test project /home/ryanliang/MySrc/cppcms-0.99.10.1/build
1/ 76 Testing base64_test
2/ 76 Testing encryptor_test
3/ 76 Testing storage_test
4/ 76 Testing json_test
5/ 76 Testing multipart_parser_test
6/ 76 Testing content_type_parser_test
7/ 76 Testing cache_backend_test
8/ 76 Testing serialization_test
9/ 76 Testing xss_test
10/ 76 Testing url_mapper_test
11/ 76 Testing copy_filter_test
12/ 76 Testing tc_test
13/ 76 Testing status_test
14/ 76 Testing async_status_test
15/ 76 Testing form_test
16/ 76 Testing cookie_test
17/ 76 Testing internal_forwarder_test
18/ 76 Testing forwarder_test
19/ 76 Testing jsonrpc_test
20/ 76 Testing http_timeouts_test_read
21/ 76 Testing http_timeouts_test_write
22/ 76 Testing file_server_test
23/ 76 Testing file_server_with_listing_test
24/ 76 Testing disco_test_http
25/ 76 Testing disco_test_fastcgi_tcp
26/ 76 Testing disco_test_scgi_tcp
27/ 76 Testing disco_test_fastcgi_unix
28/ 76 Testing disco_test_scgi_unix
29/ 76 Testing proto_test_async_http
30/ 76 Testing proto_test_async_scgi
31/ 76 Testing proto_test_async_fastcgi
32/ 76 Testing proto_test_async_scgi_unix
33/ 76 Testing proto_test_async_fastcgi_unix
34/ 76 Testing proto_test_sync_http
35/ 76 Testing proto_test_sync_scgi
36/ 76 Testing proto_test_sync_fastcgi
37/ 76 Testing proto_test_sync_scgi_unix
38/ 76 Testing proto_test_sync_fastcgi_unix
39/ 76 Testing test_function_function
40/ 76 Testing test_function_callback
41/ 76 Testing test_ptime_posix_time
42/ 76 Testing test_thread_thread
43/ 76 Testing test_thread_fork
44/ 76 Testing test_smart_ptr_shared_ptr
45/ 76 Testing test_smart_ptr_atomic_counter
46/ 76 Testing test_smart_ptr_sp_counter
47/ 76 Testing test_log_log
48/ 76 Testing test_nowide_nowide
49/ 76 Testing test_iostreams_streambuf
50/ 76 Testing test_regex_regex
51/ 76 Testing test_aio_reactor
52/ 76 Testing test_aio_timer
53/ 76 Testing test_aio_event_loop
54/ 76 Testing test_aio_socket
55/ 76 Testing test_aio_endpoint
56/ 76 Testing test_backtrace_backtrace
57/ 76 Testing test_aio_prefork
58/ 76 Testing test_locale_codepage
59/ 76 Testing test_locale_message
60/ 76 Testing test_locale_ios_prop
61/ 76 Testing test_locale_codepage_converter
62/ 76 Testing test_locale_date_time
63/ 76 Testing test_locale_generator
64/ 76 Testing test_locale_config
65/ 76 Testing test_locale_utf
66/ 76 Testing test_locale_collate
67/ 76 Testing test_locale_convert
68/ 76 Testing test_locale_boundary
69/ 76 Testing test_locale_formatting
70/ 76 Testing test_locale_icu_vs_os_timezone
71/ 76 Testing test_locale_std_convert
72/ 76 Testing test_locale_std_formatting
73/ 76 Testing test_locale_std_collate
74/ 76 Testing test_locale_posix_collate
75/ 76 Testing test_locale_posix_convert
76/ 76 Testing test_locale_posix_formatting
100% tests passed, 0 tests failed out of 76
[ryanliang@localhost build]$sudo make install
[ 18%] Built target booster
[ 38%] Built target cppcms
[ 38%] Built target base64_test
[ 38%] Built target cache_backend_test
[ 38%] Built target content_type_parser_test
[ 39%] Built target cookie_test
[ 39%] Built target copy_filter_test
[ 58%] Built target cppcms-static
[ 59%] Built target cppcms_config_find_param
[ 59%] Built target cppcms_make_key
[ 59%] Built target cppcms_scale
[ 60%] Built target disco_test
[ 60%] Built target encryptor_test
[ 60%] Built target file_server_test
[ 61%] Built target form_test
[ 61%] Built target forwarder_test
[ 63%] Built target hello_world
[ 63%] Built target http_timeouts_test
[ 63%] Built target json_test
[ 64%] Built target jsonrpc_test
[ 64%] Built target multipart_parser_test
[ 64%] Built target proto_test
[ 65%] Built target serialization_test
[ 65%] Built target skin3
[ 66%] Built target status_test
[ 66%] Built target storage_test
[ 67%] Built target tc_skin
[ 67%] Built target tc_skin_a
[ 68%] Built target tc_skin_b
[ 68%] Built target tc_test
[ 68%] Built target url_mapper_test
[ 69%] Built target xss_test
[ 87%] Built target booster-static
[ 87%] Built target test_aio_endpoint
[ 88%] Built target test_aio_event_loop
[ 88%] Built target test_aio_prefork
[ 88%] Built target test_aio_reactor
[ 89%] Built target test_aio_socket
[ 89%] Built target test_aio_timer
[ 89%] Built target test_backtrace_backtrace
[ 90%] Built target test_function_callback
[ 90%] Built target test_function_function
[ 90%] Built target test_iostreams_streambuf
[ 91%] Built target test_locale_boundary
[ 91%] Built target test_locale_codepage
[ 91%] Built target test_locale_codepage_converter
[ 92%] Built target test_locale_collate
[ 92%] Built target test_locale_config
[ 92%] Built target test_locale_convert
[ 93%] Built target test_locale_date_time
[ 93%] Built target test_locale_formatting
[ 93%] Built target test_locale_generator
[ 94%] Built target test_locale_icu_vs_os_timezone
[ 94%] Built target test_locale_ios_prop
[ 94%] Built target test_locale_message
[ 95%] Built target test_locale_posix_collate
[ 95%] Built target test_locale_posix_convert
[ 95%] Built target test_locale_posix_formatting
[ 96%] Built target test_locale_std_collate
[ 96%] Built target test_locale_std_convert
[ 96%] Built target test_locale_std_formatting
[ 97%] Built target test_locale_utf
[ 97%] Built target test_log_log
[ 97%] Built target test_nowide_nowide
[ 98%] Built target test_ptime_posix_time
[ 98%] Built target test_regex_regex
[ 98%] Built target test_smart_ptr_atomic_counter
[ 99%] Built target test_smart_ptr_shared_ptr
[ 99%] Built target test_smart_ptr_sp_counter
[ 99%] Built target test_thread_fork
[100%] Built target test_thread_thread
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /usr/lib/libcppcms.so.1.0.0
-- Installing: /usr/include/booster/bad_weak_ptr.h
-- Installing: /usr/include/booster/locale
-- Installing: /usr/include/booster/locale/date_time_facet.h
-- Installing: /usr/include/booster/locale/date_time.h
-- Installing: /usr/include/booster/locale/collator.h
-- Installing: /usr/include/booster/locale/util.h
-- Installing: /usr/include/booster/locale/encoding_errors.h
-- Installing: /usr/include/booster/locale/format.h
-- Installing: /usr/include/booster/locale/info.h
-- Installing: /usr/include/booster/locale/boundary.h
-- Installing: /usr/include/booster/locale/generator.h
-- Installing: /usr/include/booster/locale/boundary
-- Installing: /usr/include/booster/locale/boundary/facets.h
-- Installing: /usr/include/booster/locale/boundary/index.h
-- Installing: /usr/include/booster/locale/boundary/types.h
-- Installing: /usr/include/booster/locale/boundary/boundary_point.h
-- Installing: /usr/include/booster/locale/boundary/segment.h
-- Installing: /usr/include/booster/locale/hold_ptr.h
-- Installing: /usr/include/booster/locale/gnu_gettext.h
-- Installing: /usr/include/booster/locale/config.h
-- Installing: /usr/include/booster/locale/time_zone.h
-- Installing: /usr/include/booster/locale/encoding.h
-- Installing: /usr/include/booster/locale/encoding_utf.h
-- Installing: /usr/include/booster/locale/message.h
-- Installing: /usr/include/booster/locale/formatting.h
-- Installing: /usr/include/booster/locale/conversion.h
-- Installing: /usr/include/booster/locale/utf.h
-- Installing: /usr/include/booster/locale/localization_backend.h
-- Installing: /usr/include/booster/ctime.h
-- Installing: /usr/include/booster/enable_shared_from_this.h
-- Installing: /usr/include/booster/clone_ptr.h
-- Installing: /usr/include/booster/log.h
-- Installing: /usr/include/booster/copy_ptr.h
-- Installing: /usr/include/booster/refcounted.h
-- Installing: /usr/lib/libbooster.so.0.0.0
-- Installing: /usr/lib/libbooster.so.0
-- Installing: /usr/lib/libbooster.so
-- Installing: /usr/include/booster/build_config.h
-- Installing: /usr/lib/libbooster.a
-- Up-to-date: /usr/include/booster/build_config.h
[ryanliang@localhost build]$
最后安装的时候会创建下面两个目录,将头文件放在该目录下。
/usr/include/cppcms
/usr/include/booster
而在/usr/lib目录下添加了几个库文件
-- Installing: /usr/lib/libbooster.so.0.0.0
-- Installing: /usr/lib/libbooster.so.0
-- Installing: /usr/lib/libbooster.so
-- Installing: /usr/lib/libbooster.a
-- Installing: /usr/lib/libcppcms.so.1.0.0
-- Installing: /usr/lib/libcppcms.so.1
-- Installing: /usr/lib/libcppcms.so
&&&&推荐文章:
【上篇】【下篇】安全检查中...
请打开浏览器的javascript,然后刷新浏览器
< 浏览器安全检查中...
还剩 5 秒&3113人阅读
当前,越来越多的网站使用了各种框架,大部分框架使用了脚本语言、半编译语言等。比如Java、Python、Php、C#.NET等。
这些框架大部分目标是解决快速开发、运行稳定。但是,缺点是:系统庞大、运行耗费资源多、运行效率低下、占用带宽大等。
本文提出一种新的Web应用解决方案,试图针对以上缺点进行优化。
完全使用静态页面,动态数据通过Ajax访问CppCMS提供的高效Rest服务由浏览器获取。
(1)CppCMS提供Rest服务。CppCMS使用编译后的机器码运行,
效率大大提高,平均性能大概是其他语言的10倍以上(/wikipp/en/page/benchmarks)
(2)使用Json传输数据。由客户端组织展示数据,降低服务器计算时间,降低带宽使用。否则,所有HTML数据都是在
服务端生成,服务端计算压力大,并且完整的HTML数据比直接传输数据要少得多。
(3)静态数据使用Nginx服务器,可以使用优秀的Nginx性能提供稳定的服务。
以下是比较传统方法和本文提出的方法:
本文以AWS EC2的Redhat Enterprise 为例描述整个操作过程:
(1)安装CppCMS&#43;CppDB,安装过程CppCMS官网文档比较详细,不复杂,此不赘述。
(2)安装Mysql和Mysql client
(3)创建建数据库、表的脚本,使用脚本建立数据库、表
(4)程序(以CppCMS的例子程序forms为蓝本):
(4.1)插入数据
1 cppdb::pool::pointer my_pool = cppdb::pool::create(&mysql:host=127.0.0.1;database=user=password='your password'&);
2 cppdb::session sql(my_pool-&open());
5 stat = sql && &INSERT INTO t_test(test_name) VALUES(?) & && test_
6 stat.exec();
&(4.2)检索数据
1 string query = &SELECT test_name FROM t_test order by id desc limit 5&;
2 cppdb::result res = sql &&
4 result = &&ol&&;
5 while(res.next()) {
6   std::string test_
7   res &&test_
8   result &#43;= &&li&&&#43;test_name&#43;&&/li&&;
10 result &#43;= &&/ol&&;
g&#43;&#43; -Wall hello.cpp view.cpp -o hello -lcppcms -lbooster
(6)配置文件config.js
  &service& : {
    &api& : &http&,
    &port& : 8080
  &http& : {
    &script& : &/hello&
./hello -c config.js
http://ec2-35-164-231-255.us-:8080/hello/
此处注意,要去AWS EC2的控制台的安全组里设置8080端口开放,否则无法访问。
我们这里还开放Http 80端口,为Nginx监听端口。
(9)配合Nginx提供静态数据,并提供Rest服务的反向代理
(9.1)安装Nginx
(9.2)配置Nginx
location / { #提供静态页面
root /data/
location /hello/ { #反向代理到CppCMS的Rest服务
proxy_pass http://localhost:8080/
location ~ \.(gif|jpg|png)$ { #图像
root /data/
(9.3)使用新的配置文件启动Nginx后可以做如下测试:
(A)http://ec2-35-164-231-255.us- 这个导向了Nginx提供的静态页面
(B)http://ec2-35-164-231-255.us-/hello 这个导向了CppCMS提供的一个页面,可以输入名称,点击提交,把数据保存
(C)使用Ajax的目前还没有实现,等下次再说
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:475646次
积分:7367
积分:7367
排名:第3406名
原创:239篇
(1)(49)(190)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'}

我要回帖

更多关于 隐藏端口 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信