首页 > 代码库 > ubuntu 12.04 server 安装nginx

ubuntu 12.04 server 安装nginx

  1. 下载源码:

     wget http://nginx.org/download/nginx-1.6.1.tar.gz

  2. 解压,编译安装

./configure

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

    

$ sudo apt-get install pcre-devel

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

E: 未发现软件包 pcre-devel

下载安装pcre库:

官网:http://www.pcre.org/
下载页面:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
选择最新版本下载:

    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz

 

./configure
make
sudo make install

启动nginx:

  error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

参考:error while loading shared libraries: xxx.so.x"错误的原因和解决办法 

查找libpcre.so.1所在位置为 /usr/local/lib

~$ cat /etc/ld.so.conf

include /etc/ld.so.conf.d/*.conf


/usr/local/ssl/lib


sudo su
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

再次启动:

$ sudo /usr/local/nginx/sbin/nginx

如果80端口未被占用,则在浏览器输入IP显示:

wKiom1PsdEKQkwAgAAFLeh0Ov5M739.jpg

nginx 服务器重启命令,关闭 

nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确
关闭nginx:
nginx -s stop  :快速停止nginx
         quit  :完整有序的停止nginx
其他的停止nginx 方式:
ps -ef | grep nginx
kill -QUIT 主进程号     :从容停止Nginx
kill -TERM 主进程号     :快速停止Nginx
pkill -9 nginx          :强制停止Nginx
启动nginx:
nginx -c /path/to/nginx.conf
平滑重启nginx:
kill -HUP 主进程号

    在Nginx中设置反向代理,在"/usr/local/nginx/conf/nginx.conf"中,添加下面的

配置:proxy_pass http://127.0.0.1:9000;

wKioL1Psd9PS7-ieAACU-SKISuU425.jpg

sudo /usr/local/nginx/sbin/nginx -s reload
sudo node http-remote-test.js

再次从浏览器中输入IP,则网页定位到9000端口:

wKiom1Psdz7C9uqvAAA396a_wEQ655.jpg

$ cat http-remote-test.js

var http = require(‘http‘)

http.createServer(function(req, res) {

    res.writeHead(200, {‘Content-Type‘: ‘Text/html‘});

        res.write(‘<h1>Node.js</h1>‘);

    res.end(‘<p>Hello World!</p>‘);

    }).listen(9000);

console.log(‘Server running at port 9000‘);


本文出自 “飒飒秋风” 博客,请务必保留此出处http://xjhznick.blog.51cto.com/3608584/1540037