﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-朱的工作记录-文章分类-Web Server</title><link>http://www.cppblog.com/van201314/category/18564.html</link><description>技术博客</description><language>zh-cn</language><lastBuildDate>Tue, 28 Feb 2012 17:02:56 GMT</lastBuildDate><pubDate>Tue, 28 Feb 2012 17:02:56 GMT</pubDate><ttl>60</ttl><item><title>nginx-1.0.12交叉编译</title><link>http://www.cppblog.com/van201314/articles/165661.html</link><dc:creator>朱</dc:creator><author>朱</author><pubDate>Wed, 15 Feb 2012 04:45:00 GMT</pubDate><guid>http://www.cppblog.com/van201314/articles/165661.html</guid><wfw:comment>http://www.cppblog.com/van201314/comments/165661.html</wfw:comment><comments>http://www.cppblog.com/van201314/articles/165661.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/van201314/comments/commentRss/165661.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/van201314/services/trackbacks/165661.html</trackback:ping><description><![CDATA[编译器:&nbsp;mipsel-linux-uclibc-gcc<br />环境：suse 9<br />软件：nginx-1.0.12和openssl-1.0.0g<br /><br />使用gcc编译和顺利，直接使用./configure --without-pcre --with-http_ssl_module --with-openssl=/home/openssl-1.0.0g --without-http_rewrite_module<br /><div>即可顺利make。在objs目录下就有生成的nginx程序。拷贝conf目录下的nginx.conf和html目录到objs下。修改nginx.conf配置。创建logs/errors.log文件。然后</div>./nginx -c&nbsp;nginx.conf<div>测试OK。</div><br />查了下，发现nginx本身不支持交叉编译。修改自己修改来支持。使用以下配置，发现出现很多错误。一个个改，看看能不能OK<br /><div>./configure --without-pcre --with-http_ssl_module --with-openssl=/home/openssl-1.0.0g --without-http_rewrite_module --with-cc=/opt/mv_tools/bin/mipsel-linux-uclibc-gcc --with-cpp=/opt/mv_tools/bin/mipsel-linux-uclibc-g++ --with-ld-opt="-s -Wl,-rpath,::/mnt/:./" --without-http_gzip_module --crossbuild=cross-linux-32<br /><br />因为nginx不支持交叉编译，只好把gcc替换成交叉编译器，修改auto/cc/gcc文件，尽量去掉和gcc有关的参数，只剩下<br /><div><div>ngx_feature="gcc"</div><div>ngx_feature_name=</div><div>ngx_feature_run=no</div><div>ngx_feature_incs=</div><div>ngx_feature_path=</div><div>ngx_feature_libs=</div><div>ngx_feature_test=</div><div>. auto/feature</div></div><br />修改auto/feature文件，去掉：<br /><div><div>ngx_feature="localtime_r()"</div><div>ngx_feature_name="NGX_HAVE_LOCALTIME_R"</div><div>ngx_feature_run=no</div></div><br />修改auto/types/sizeof文件，将ngx_size赋值为4，同时去掉<br /><div><div>cat &lt;&lt; END &gt; $NGX_AUTOTEST.c</div><div></div><div>#include &lt;sys/types.h&gt;</div><div>#include &lt;sys/time.h&gt;</div><div>$NGX_INCLUDE_UNISTD_H</div><div>#include &lt;signal.h&gt;</div><div>#include &lt;sys/resource.h&gt;</div><div>$NGX_INCLUDE_INTTYPES_H</div><div>$NGX_INCLUDE_AUTO_CONFIG_H</div><div></div><div>int main() {</div><div>&nbsp; &nbsp; printf("%d", sizeof($ngx_type));</div><div>&nbsp; &nbsp; return 0;</div><div>}</div><div></div><div>END</div></div><br /><div>修改auto/types/typedef文件，去掉&nbsp;END下面的所以内容。</div><br />因为需要用到pre库，可以修改auto/lib/pre/make文件，在配置那行改成：<br /><div>./configure --disable-shared --host=mipsel-linux-uclibc<br /><br />用到openssl库，可以修改auto/lib/openssl/make文件，修改配置那行为：<br /><div>&amp;&amp; ./Configure --prefix=$ngx_prefix no-shared linux-mipsel-ti:mipsel-linux-uclibc-gcc no-threads no-cast no-mdc2 no-rc2 no-rc5 no-krb5 \\</div></div>出现NGX_SYS_NERR未定义问题，试过其他办法都不行，最后只好在源文件ngx_error.c里面直接定义个值，<br />#define NGX_SYS_NERR 125//随便定义的，可能会有问题<br /><br />出现ngx_shm_alloc未定义货找不到问题，使用mipsel-linux-uclibc-nm才知道函数没被编译进去，修改src/os/unix/ngx_shm.c，打开NGX_HAVE_MAP_ANON编译条件。<br /><br />编译通过后，就可以在目标平台上运行了。测试了下，速度还行，感觉和Goahead差不多。试了下CGI，才发现nginx不能直接支持CGI。。查了下，可以支持fast-cgi，还是得通过其他模块来跑才可以，比如spawn-fcgi，可惜折腾过去，还是不行（spawn-fcgi一运行就没了，根本没在监听端口，搞不懂这个）。郁闷。暂时没时间继续搞这个。先记录下，待续。。</div><img src ="http://www.cppblog.com/van201314/aggbug/165661.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/van201314/" target="_blank">朱</a> 2012-02-15 12:45 <a href="http://www.cppblog.com/van201314/articles/165661.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Webs-2-5的使用（goahead）</title><link>http://www.cppblog.com/van201314/articles/165118.html</link><dc:creator>朱</dc:creator><author>朱</author><pubDate>Tue, 07 Feb 2012 11:54:00 GMT</pubDate><guid>http://www.cppblog.com/van201314/articles/165118.html</guid><wfw:comment>http://www.cppblog.com/van201314/comments/165118.html</wfw:comment><comments>http://www.cppblog.com/van201314/articles/165118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/van201314/comments/commentRss/165118.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/van201314/services/trackbacks/165118.html</trackback:ping><description><![CDATA[交叉编译器：mipsel-linux-uclibc-gcc<br />环境：suse 9<br /><br />1.下载解压（包括matrixssl-3-1-2-open，因为需要用到这个ssl库）<br /><div>matrixssl-3-1-2-open这个库放在webs-2-5目录里面。</div>2.编译<br />修改matrixssl-3-1-2-open的Makefile<br /><div>CC &nbsp; &nbsp; &nbsp;= mipsel-linux-uclibc-gcc<br /><div>STRIP &nbsp; = mipsel-linux-uclibc-strip</div><div>AR &nbsp; &nbsp; &nbsp;= mipsel-linux-uclibc-ar</div></div><div>#make</div>生成libmatrixssl.a<br /><br /><div>修改LINUX/Makefile：<br />CC &nbsp; &nbsp; &nbsp;= mipsel-linux-uclibc-gcc<br /><div>STRIP &nbsp; = mipsel-linux-uclibc-strip</div><div>AR &nbsp; &nbsp; &nbsp;= mipsel-linux-uclibc-ar</div></div>修改main.c：<br /><div><div style="font-family: 'Courier New'; font-size: 14pt; color: #ffffff; background-color: #29382f; text-decoration: none; "> <pre><span style="color:#ffff00;">static</span> char_t       *rootWeb = T(<span style="color:#00ff00;">"www"</span>);            <span style="color:#00f5ff;">/* Root web directory */</span> <br /><span style="color:#ffff00;">static</span> char_t       *demoWeb = T(<span style="color:#00ff00;">"wwwdemo"</span>);        <span style="color:#00f5ff;">/* Root web directory */</span></pre></div></div>这个是webs程序跑的html目录<br /><br /><div><div style="font-family: 'Courier New'; font-size: 14pt; text-decoration: none; background-color: #29382f; "> <pre><span style="color: #00f5ff; ">/*if (gethostname(host, sizeof(host)) &lt; 0) <br />{</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">  <br />    error(E_L, E_LOG, T("Can't get hostname"));</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">        <br /></span><span style="color: #00f5ff; ">    return -1;</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">    <br />}</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">    <br />if ((hp = gethostbyname(host)) == NULL) <br />{</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">        <br />    error(E_L, E_LOG, T("Can't get host address"));</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">        <br />    return -1;</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">    <br />}</span><font color="#ffffff"> </font><span style="color: #00f5ff; ">    <br />memcpy((char *) &amp;intaddr, (char *) hp-&gt;h_addr_list[0],</span><span style="color: #00f5ff; ">(size_t) hp-&gt;h_length);*/</span><font color="#ffffff">     <br />intaddr.s_addr=inet_addr(</font><span style="color: #00ff00; ">"10.2.11.195"</span><font color="#ffffff">);</font><span style="color: #00f5ff; ">//替换成自身IP，因为在MIPS平台无法通过上面的函数获取IP</span></pre></div></div><div><div style="font-family: 'Courier New'; font-size: 14pt; background-color: #29382f; text-decoration: none; "> <pre style="color: #ffffff; "><span style="color:#00f5ff;">/*getcwd(dir, sizeof(dir)); </span> <span style="color:#00f5ff;">    <br />if ((cp = strrchr(dir, '/'))) <br />{</span> <span style="color:#00f5ff;">        <br />    *cp = '\0';</span> <span style="color:#00f5ff;">    <br />}*/</span>    <br /><span style="color: #ff8040; ">strcpy</span>(dir, <span style="color:#00ff00;">"/mnt"</span>);<span style="font-family: 'Courier New'; font-size: 14pt; color: #00f5ff; ">//直接赋值html所在的目录路径，因为使用上面的函数获取，出现404</span></pre></div></div><div><div style="font-family: 'Courier New'; font-size: 14pt; color: #ffffff; background-color: #29382f; text-decoration: none; "> <pre><span style="color: #00f5ff; ">//ascToUni(wbuf, host, min(strlen(host) + 1, sizeof(wbuf)));//屏蔽这一行</span></pre></div></div>#make<br />即可在当前目录下生成webs程序，拷贝到目标平台测试运行（可以使用源码提供的wwwdemo作html测试）<br /><br />3.运行<br />./webs -demo（运行wwwdemo里面的html）<img src ="http://www.cppblog.com/van201314/aggbug/165118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/van201314/" target="_blank">朱</a> 2012-02-07 19:54 <a href="http://www.cppblog.com/van201314/articles/165118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>