欢迎来到梦飞科技

服务器租用

当前优惠活动:

Nginx服务的详细安装部署步骤

Nginx ("engine x") 是一个高机能的 HTTP 和 反向署理 处事器,也是一个 IMAP/POP3/SMTP 署理处事器。 Nginx 是由 Igor Sysoev 为俄罗斯会见量第二的 Rambler.ru 站点开拓的,第一个果真版本0.1.0宣布于2004年10月4日。其将源代码以类BSD许可证的形式宣布,台湾代理服务器 韩国服务器,因它的不变性、富厚的成果集、示例设置文件和低系统资源的耗损而闻名。2011年6月1日,nginx 1.0.4宣布。

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

1.选定源码目次

选定目次 /usr/local/

cd /usr/local/

 安装C++支持:yum install -y gcc-c++

2.安装PCRE库

cd /usr/local/

下载地点:pcre:http://sourceforge.net/projects/pcre/files/ 

wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz/download

tar -zxvf pcre-8.21.tar.gz

cd pcre-8.21

./configure

make

make install

3.安装zlib库

cd /usr/local/ 

wget http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

./configure

make

make install

4.安装ssl

cd /usr/local/

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

tar -zxvf openssl-1.0.1c.tar.gz

./config

make

make install

5.安装nginx

Nginx 一般有两个版本,别离是不变版和开拓版,您可以按照您的目标来选择这两个版本的个中一个,下面是把 Nginx 安装到 /usr/local/nginx 目次下的具体步调:

cd /usr/local/

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

tar -zxvf nginx-1.2.8.tar.gz

cd nginx-1.2.8  

./configure --prefix=/usr/local/nginx 

make

make install

--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.21 的源码路径。

--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。

6.启动

确保系统的 80 端口没被其他措施占用,

/usr/local/nginx/sbin/nginx

查抄是否启动乐成:

netstat -ano|grep 80 有功效输入说明启动乐成

打开欣赏器会见此呆板的 IP,假如欣赏器呈现 Welcome to nginx! 则暗示 Nginx 已经安装并运行乐成。

7.重启

 /usr/local/nginx/sbin/nginx -s reload

8.修改设置文件

cd /usr/local/nginx/conf

vi nginx.conf

9.常用设置

#nginx运行用户和组

user    www www;  

#启动历程,凡是配置成和cpu的数量相等

worker_processes  4;

#全局错误日志及PID文件

pid /var/run/nginx.pid;

error_log  /var/log/nginx/error.log;

events {

        #epoll是多路复用IO(I/O Multiplexing)中的一种方法,可是仅用于linux2.6以上内核,可以大大提高nginx的机能

use epoll;

                   #单个靠山worker process历程的最大并发链接数

        worker_connections  10240;

}

#设定http处事器,操作它的反向署理成果提供负载平衡支持

http {

        include       mime.types;

        default_type  application/octet-stream;

         error_page 400 403 500 502 503 504  /50x.html;

        index index.html index.shtml

        autoindex off;

         fastcgi_intercept_errors on;

        sendfile        on;

        # These are good default values.

        tcp_nopush      on;

        tcp_nodelay     off;

        # output compression saves bandwidth

        gzip  off;

         #gzip_static on;

        #gzip_min_length  1k;

        gzip_http_version 1.0;

        gzip_comp_level 2;

        gzip_buffers  4 16k;

        gzip_proxied any;

        gzip_disable "MSIE [1-6]\.";

        gzip_types  text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;

        #gzip_vary on;

        server_name_in_redirect off;

#设定负载平衡的处事器列表

        upstream portals {

                  server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;

                  server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;

梦飞科技 - 全球数据中心基础服务领先供应商

Copyright © 2003-2019 MFISP.COM. 国外服务器租用 IDC公司 版权所有 粤ICP备11019662号