欢迎光临
我们一直在努力

[Centos]编译安装Nginx

1、安装LuaJIT

<span class="com">#下载地址:http://luajit.org/download.html</span>
<span class="com">#         https://github.com/openresty/lua-nginx-module/tags</span>
<span class="com">#         https://github.com/simplresty/ngx_devel_kit/tags</span>
<span class="com">#工具包 https://gitee.com/bbhsky/Nginx-Setup.git</span><span class="pln">
tar zxvf </span><span class="typ">LuaJIT</span><span class="pun">-</span><span class="lit">2.0</span><span class="pun">.</span><span class="lit">5.tar</span><span class="pun">.</span><span class="pln">gz
cd </span><span class="typ">LuaJIT</span><span class="pun">-</span><span class="lit">2.0</span><span class="pun">.</span><span class="lit">5</span><span class="pun">/</span><span class="pln">
make
make install PREFIX</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">-</span><span class="lit">2.0</span><span class="pun">.</span><span class="lit">5</span><span class="pln">
ln </span><span class="pun">-</span><span class="pln">sf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">-</span><span class="lit">2.0</span><span class="pun">.</span><span class="lit">5</span><span class="str">/ /</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit
cat </span><span class="pun">></span> <span class="str">/etc/</span><span class="pln">ld</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">.</span><span class="pln">conf</span><span class="pun"><<</span><span class="pln">EOF
</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">/</span><span class="pln">lib
EOF
ln </span><span class="pun">-</span><span class="pln">sf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">libluajit</span><span class="pun">-</span><span class="lit">5.1</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="lit">2</span> <span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib64</span><span class="pun">/</span><span class="pln">libluajit</span><span class="pun">-</span><span class="lit">5.1</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="lit">2</span><span class="pln">
ln </span><span class="pun">-</span><span class="pln">sf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">libluajit</span><span class="pun">-</span><span class="lit">5.1</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="lit">2</span> <span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">libluajit</span><span class="pun">-</span><span class="lit">5.1</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="lit">2</span><span class="pln">
cat </span><span class="pun">></span><span class="str">/etc/</span><span class="pln">profile</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">.</span><span class="pln">sh</span><span class="pun"><<</span><span class="pln">EOF
</span><span class="kwd">export</span><span class="pln"> LUAJIT_LIB</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">/</span><span class="pln">lib
</span><span class="kwd">export</span><span class="pln"> LUAJIT_INC</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">/</span><span class="pln">include</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">-</span><span class="lit">2.0</span><span class="pln">
EOF</span>

2、下载扩展模块:

2.1、合并CSS、JS  nginx-http-concat

<span class="com">#下载地址:git://github.com/alibaba/nginx-http-concat.git</span>
<span class="com">#工具包 https://gitee.com/bbhsky/Nginx-Setup.git</span><span class="pln">
git clone git</span><span class="pun">:</span><span class="com">//github.com/alibaba/nginx-http-concat.git</span><span class="pln">
mv nginx</span><span class="pun">-</span><span class="pln">http</span><span class="pun">-</span><span class="pln">concat </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx_module</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="pln">http</span><span class="pun">-</span><span class="pln">concat

</span><span class="pun">===============</span><span class="pln">conf</span><span class="pun">文件使用方法==========================</span><span class="pln">
location </span><span class="pun">/</span><span class="kwd">static</span><span class="pun">/</span><span class="pln">css</span><span class="pun">/</span> <span class="pun">{</span><span class="pln">
    concat on</span><span class="pun">;</span><span class="pln">
    concat_max_files </span><span class="lit">20</span><span class="pun">;</span>
<span class="pun">}</span><span class="pln">
location </span><span class="pun">/</span><span class="kwd">static</span><span class="pun">/</span><span class="pln">js</span><span class="pun">/</span> <span class="pun">{</span><span class="pln">
    concat on</span><span class="pun">;</span><span class="pln">
    concat_max_files </span><span class="lit">30</span><span class="pun">;</span>
<span class="pun">}</span><span class="pln">
location </span><span class="pun">/</span><span class="kwd">static</span><span class="pun">/</span> <span class="pun">{</span><span class="pln">
    concat on</span><span class="pun">;</span><span class="pln">
    concat_max_files </span><span class="lit">20</span><span class="pun">;</span><span class="pln">
    concat_unique off</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pun">页面使用方法:</span>
<span class="pun"><</span><span class="pln">link rel</span><span class="pun">=</span><span class="str">"stylesheet"</span><span class="pln"> href</span><span class="pun">=</span><span class="str">"??foo1.css,foo2.css,subdir/foo3.css?v=2345"</span> <span class="pun">/></span>
<span class="pun"><</span><span class="pln">script src</span><span class="pun">=</span><span class="str">"??bar1.js,bar22.css,subdir/bar3.js?v=3245"</span> <span class="pun">/></span>
<span class="pun">========================配置参数======================</span>
<span class="pun">参数:</span><span class="pln">concat on </span><span class="pun">|</span><span class="pln"> off
</span><span class="pun">说明:是否开启功能</span>
<span class="pun">默认:</span><span class="kwd">default</span><span class="pun">:</span><span class="pln"> concat off
</span><span class="pun">环境:</span><span class="pln">context</span><span class="pun">:</span><span class="pln"> http</span><span class="pun">,</span><span class="pln"> server</span><span class="pun">,</span><span class="pln"> location

</span><span class="pun">参数:</span><span class="pln">concat_types MIME types
</span><span class="pun">说明:功能类型文件</span>
<span class="pun">默认:</span><span class="kwd">default</span><span class="pun">:</span><span class="pln"> concat_types</span><span class="pun">:</span><span class="pln"> text</span><span class="pun">/</span><span class="pln">css application</span><span class="pun">/</span><span class="pln">x</span><span class="pun">-</span><span class="pln">javascript
</span><span class="pun">环境:</span><span class="pln">context</span><span class="pun">:</span><span class="pln"> http</span><span class="pun">,</span><span class="pln"> server</span><span class="pun">,</span><span class="pln"> location

</span><span class="pun">参数:</span><span class="pln">concat_unique on </span><span class="pun">|</span><span class="pln"> off
</span><span class="pun">说明:是否只允许同类型文件</span>
<span class="pun">默认:</span><span class="kwd">default</span><span class="pun">:</span><span class="pln"> concat_unique on
</span><span class="pun">环境:</span><span class="pln">context</span><span class="pun">:</span><span class="pln"> http</span><span class="pun">,</span><span class="pln"> server</span><span class="pun">,</span><span class="pln"> location

</span><span class="pun">参数:</span><span class="pln">concat_max_files number p
</span><span class="pun">说明:最大允许文件个数</span>
<span class="pun">默认:</span><span class="kwd">default</span><span class="pun">:</span><span class="pln"> concat_max_files </span><span class="lit">10</span>
<span class="pun">环境:</span><span class="pln">context</span><span class="pun">:</span><span class="pln"> http</span><span class="pun">,</span><span class="pln"> server</span><span class="pun">,</span><span class="pln"> location

</span><span class="pun">参数:</span><span class="pln">concat_delimiter</span><span class="pun">:</span> <span class="kwd">string</span>
<span class="pun">说明:自定义分隔符,一般默认为</span><span class="str">","</span>
<span class="pun">默认:</span><span class="kwd">default</span><span class="pun">:</span><span class="pln"> NONE
</span><span class="pun">环境:</span><span class="pln">context</span><span class="pun">:</span><span class="pln"> http</span><span class="pun">,</span><span class="pln"> server</span><span class="pun">,</span><span class="pln"> locatione

</span><span class="pun">参数:</span><span class="pln">concat_ignore_file_error</span><span class="pun">:</span><span class="pln"> on </span><span class="pun">|</span><span class="pln"> off
</span><span class="pun">说明:</span> <span class="pun">是否忽略文件请求错误,例如</span><span class="lit">404</span><span class="pun">和</span><span class="lit">403</span><span class="pun">等</span>
<span class="pun">默认:</span><span class="kwd">default</span><span class="pun">:</span><span class="pln"> off
</span><span class="pun">环境:</span><span class="pln">context</span><span class="pun">:</span><span class="pln"> http</span><span class="pun">,</span><span class="pln"> server</span><span class="pun">,</span><span class="pln"> location</span>

3、编译安装Nginx

<span class="com">#下载地址:http://nginx.org/en/download.html</span>
<span class="com">#工具包 https://gitee.com/bbhsky/Nginx-Setup.git</span><span class="pln">
tar zxvf nginx</span><span class="pun">-</span><span class="lit">1.15</span><span class="pun">.</span><span class="lit">3.tar</span><span class="pun">.</span><span class="pln">gz
cd nginx</span><span class="pun">-</span><span class="lit">1.15</span><span class="pun">.</span><span class="lit">3</span><span class="pln">
groupadd www
useradd </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">nologin </span><span class="pun">-</span><span class="pln">g www www
</span><span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">user</span><span class="pun">=</span><span class="pln">www </span><span class="pun">--</span><span class="kwd">group</span><span class="pun">=</span><span class="pln">www </span><span class="pun">--</span><span class="pln">prefix</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="lit">1.15</span><span class="pun">.</span><span class="lit">3</span> <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">http_stub_status_module </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">http_ssl_module </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">http_v2_module </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">http_gzip_static_module </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">http_sub_module </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">stream </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">stream_ssl_module </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">openssl</span><span class="pun">=</span><span class="str">/root/</span><span class="pln">src</span><span class="pun">/</span><span class="typ">Centos7</span><span class="pun">-</span><span class="pln">setup</span><span class="pun">/</span><span class="pln">openssl</span><span class="pun">-</span><span class="lit">1.1</span><span class="pun">.</span><span class="lit">0</span><span class="pun">-</span><span class="pln">stable</span><span class="pun">-</span><span class="pln">SNAP</span><span class="pun">-</span><span class="lit">20180901</span><span class="pun">/</span> <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">ld</span><span class="pun">-</span><span class="pln">opt</span><span class="pun">=-</span><span class="typ">Wl</span><span class="pun">,-</span><span class="pln">rpath</span><span class="pun">,</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">luajit</span><span class="pun">/</span><span class="pln">lib </span><span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="kwd">module</span><span class="pun">=</span><span class="str">/root/</span><span class="pln">src</span><span class="pun">/</span><span class="typ">Nginx</span><span class="pun">-</span><span class="typ">Setup</span><span class="pun">/</span><span class="pln">lua</span><span class="pun">-</span><span class="pln">nginx</span><span class="pun">-</span><span class="kwd">module</span><span class="pun">-</span><span class="lit">0.10</span><span class="pun">.</span><span class="lit">13</span> <span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="kwd">module</span><span class="pun">=</span><span class="str">/root/</span><span class="pln">src</span><span class="pun">/</span><span class="typ">Nginx</span><span class="pun">-</span><span class="typ">Setup</span><span class="pun">/</span><span class="pln">ngx_devel_kit</span><span class="pun">-</span><span class="lit">0.3</span><span class="pun">.</span><span class="lit">0</span> <span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="kwd">module</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx_module</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="pln">http</span><span class="pun">-</span><span class="pln">concat</span><span class="pun">/</span>
<span class="com">#如果报错lua的 执行 yum install lua-devel</span><span class="pln">
make </span><span class="pun">&&</span><span class="pln"> make install
ln </span><span class="pun">-</span><span class="pln">sf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="lit">1.15</span><span class="pun">.</span><span class="lit">3</span><span class="str">/ /</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx
ln </span><span class="pun">-</span><span class="pln">sf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">nginx </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">nginx
mv </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">conf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">bak
cp conf</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">conf </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">conf
cp </span><span class="pun">-</span><span class="pln">ra conf</span><span class="pun">/</span><span class="pln">rewrite </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">rewrite
sed </span><span class="pun">-</span><span class="pln">i </span><span class="str">"/location \/nginx_status/i\        location /lua\n        {\n            default_type text/html;\n            content_by_lua 'ngx.say\(\"hello world\"\)';\n        }\n"</span> <span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">conf
mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">wwwroot
chmod </span><span class="pun">+</span><span class="pln">w </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">wwwroot
mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">wwwlogs
chmod </span><span class="lit">777</span> <span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">wwwlogs
mkdir </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">vhost
mkdir </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">wwwroot</span><span class="pun">/</span><span class="kwd">default</span><span class="pln">
chown </span><span class="pun">-</span><span class="pln">R www</span><span class="pun">:</span><span class="pln">www </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">wwwroot
cat </span><span class="pun">>></span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">fastcgi</span><span class="pun">.</span><span class="pln">conf</span><span class="pun"><<</span><span class="pln">EOF
fastcgi_param PHP_ADMIN_VALUE </span><span class="str">"open_basedir=\$document_root/:/tmp/:/proc/"</span><span class="pun">;</span><span class="pln">
EOF
cp init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx
chmod </span><span class="pun">+</span><span class="pln">x </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx
</span><span class="com">#创建系统服务</span><span class="pln">
vim </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">systemd</span><span class="pun">/</span><span class="pln">system</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">service

</span><span class="pun">[</span><span class="typ">Unit</span><span class="pun">]</span>
<span class="typ">Description</span><span class="pun">=</span><span class="typ">The</span><span class="pln"> NGINX HTTP server
</span><span class="typ">After</span><span class="pun">=</span><span class="pln">syslog</span><span class="pun">.</span><span class="pln">target network</span><span class="pun">.</span><span class="pln">target remote</span><span class="pun">-</span><span class="pln">fs</span><span class="pun">.</span><span class="pln">target nss</span><span class="pun">-</span><span class="pln">lookup</span><span class="pun">.</span><span class="pln">target

</span><span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span>
<span class="typ">Type</span><span class="pun">=</span><span class="pln">forking
</span><span class="typ">PIDFile</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">logs</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">pid
</span><span class="typ">ExecStartPre</span><span class="pun">=</span><span class="str">/usr/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">nginx </span><span class="pun">-</span><span class="pln">t
</span><span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/usr/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">nginx
</span><span class="typ">ExecReload</span><span class="pun">=</span><span class="str">/bin/</span><span class="pln">kill </span><span class="pun">-</span><span class="pln">s HUP $MAINPID
</span><span class="typ">ExecStop</span><span class="pun">=</span><span class="str">/bin/</span><span class="pln">kill </span><span class="pun">-</span><span class="pln">s QUIT $MAINPID
</span><span class="typ">PrivateTmp</span><span class="pun">=</span><span class="kwd">true</span>

<span class="pun">[</span><span class="typ">Install</span><span class="pun">]</span>
<span class="typ">WantedBy</span><span class="pun">=</span><span class="pln">multi</span><span class="pun">-</span><span class="pln">user</span><span class="pun">.</span><span class="pln">target


systemctl enable nginx</span><span class="pun">.</span><span class="pln">service
systemctl start nginx</span><span class="pun">.</span><span class="pln">service</span>

遇见的错误:

 <span class="pun">./</span><span class="pln">configure</span><span class="pun">:</span><span class="pln"> error</span><span class="pun">:</span><span class="pln"> ngx_http_lua_module requires the </span><span class="typ">Lua</span><span class="pln"> library</span><span class="pun">.</span><span class="pln">
yum install </span><span class="pun">-</span><span class="pln">y lua</span><span class="pun">-</span><span class="pln">devel</span>
赞(0)
未经允许不得转载:798VPS » [Centos]编译安装Nginx
分享到: 更多 (0)