Linux安装Nginx的方法

来源:互联网 发布:广告排版设计软件 编辑:程序博客网 时间:2024/06/14 01:20

转自:http://www.codingyun.com/article/42.html

可以先下载到本地,然后ftp到服务器

官方Nginx 的下载页面:

1
http://nginx.org/en/download.html

也可以直接在服务器下载(windows版本的区分32位与64位,ubuntu(linux)版本的不区分)

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

或者可以到我的共享云盘下载

1
http://yunpan.cn/QaIskk4i6LrrR  访问密码 cc22

二、准备工作

首先,创建相应的目录

1
2
3
4
5
userdel www
groupadd www
mkdir -p /alidata/www
mkdir -p /alidata/server/nginx
useradd -g www -M -d /alidata/www -s /sbin/nologin www &> /dev/null

三、解压

我一般都会把文件下载到/root/softDown

因此nginx的tar文件也在这个目录下

1
2
tar zxvf nginx-1.6.1.tar.gz
cd nginx-1.6.1
当前所在目录/root/softDown/nginx-1.6.1

执行以下命令,命令如果太长,可以换行,换行符为\

1
2
3
4
5
6
7
./configure --user=www \
--group=www \
--prefix=/alidata/server/nginx \
--with-http_stub_status_module \
--without-http-cache \
--with-http_ssl_module \
--with-http_gzip_static_module

如果报错的话,如下的错误:

./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=option.

代表依赖的OpenSSL library包还没有安装(上面阿里云提供的sh脚本少了这个library依赖,这里我们自己下载安装)

所以先下载依赖包,执行以下命令,安装该OpenSSL library

1
2
apt-get update
apt-get install openssl libssl-dev

如果报错PCRE library没有安装,则下载安装

1
sudo apt-get install libpcre3 libpcre3-dev
这样的话缺少的依赖包安装好了,就可以继续安装nginx了
1
2
3
4
5
6
7
8
cd  /root/softDown/nginx-1.6.1
./configure --user=www \
--group=www \
--prefix=/alidata/server/nginx \
--with-http_stub_status_module \
--without-http-cache \
--with-http_ssl_module \
--with-http_gzip_static_module

四、编译,安装

make -jn (n = cpu核心x2)的多线程编译的参数

我的服务器是2核的,所以用的是make -j4 (所以你的是x核,那么这里就是make -j2x)

1
make -j4 
执行安装
1
2
3
4
5
6
7
8
make install
chmod775/alidata/server/nginx/logs
chown -R www:www /alidata/server/nginx/logs
chmod -R 775/alidata/www
chown -R www:www /alidata/www
chmod755/alidata/server/nginx/sbin/nginx
mv /alidata/server/nginx/sbin/nginx /etc/init.d/
chmod +x /etc/init.d/nginx
五、运行
1
/etc/init.d/nginx

六、测试验证

安装成功后 /usr/local/www/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。 其中 Nginx 的配置文件存放于 conf/nginx.conf,Nginx 只有一个程序文件位于 sbin 目录下的 nginx 文件。 确保系统的 80 端口没被其他程序占用,运行 sbin/nginx 命令来启动 Nginx,打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

0 0
原创粉丝点击