您的位置:首页 > 运维架构 > Nginx

Linux系统下Nginx服务器部署

2016-02-04 00:00 639 查看
Nginx安装步骤:

一、相关组件

(1) Nginx本身

下载地址:http://nginx.org/en/download.html;提供的安装包是Nginx-1.9.7版本。

(2) Rewrite模块的正则表达式依赖库pcre
下载地址:http://www.pcre.org;提供的安装包是pcre-8.38版本。

二、安装步骤

(1) 安装pcre

tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make
make install
默认安装到/usr/local/lib下即可;安装完成后可以#ls -l /usr/local/lib/libpcre.so
(2) 安装nginx

tar –zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7
./configure
make
make install

三、nginx配置

配置文件默认在/usr/local/nginx目录下,主要的配置文件为conf目录下的nginx.conf。
启动程序文件在/usr/sbin/nginx中。
日志在/var/log/nginx中,分别是access.log和error.log。
默认的虚拟主机的目录设置在了/usr/share/nginx/html中。
常见配置如下:
(1) 侦听80端口 (nginx默认监听80端口)
listen 80;

(2) 服务器名称
Server_name localhost;

(3) 默认主页目录在nginx安装目录的html子目录。
root html;

index index.html index.html;

四、管理nginx

(1) 启动

/usr/local/nginx/sbin/nginx (/usr/nginx/sbin/nginx -t 查看配置信息是否正确)
(2) 停止

/usr/local/nginx/sbin/nginx -s stop
(3) 重启
/usr/local/nginx/sbin/nginx -s reload
(4) 查看状态

netstat -autlp| grep nginx
(5) 检查部署正确性

访问http://localhost/,查看是否正常启动。

五、常见问题

(1) 缺少pcre库:./configure: error: the HTTP rewrite module requires the PCRE library.
解决方法:安装pcre。
(2) 缺少openssl:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
解决方法:安装openssl-devel。
(3) 缺少gcc-c++和libtool:The program 'libtool' is currently not installed. You can install it by typing:sudo apt-get install libtool
解决方法:安装libtool和gcc-c++。

(4) 缺少zlib:./configure: error: the HTTP gzip module requires the zlib library.

解决方法:安装zlib。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux nginx