环境:

  centos 7

  防火墙关闭

  Selinx关闭

Nginx Web安装
  安装依赖库
    yum install pcre-devel pcre gcc gcc-c++ zlib zlib-devel openssl openssl-devel -y (pcre库主要用于nginx正则表达)
  下载Nginx源码包
    cd /softwares
    wget -c http://nginx.org/download/nginx-1.4.2.tar.gz
    tar -xvzf nginx-1.4.2.tar.gz
  预编译、编译Nginx
    cd nginx-1.4.2
    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make && make install
  检查nginx是否安装正确
    /usr/local/nginx/sbin/nginx  -t    # 返回OK即为安装成功

nginx.conf配置文件详解 (cd /usr/local/nginx/conf)

#user  nobody;      # Nginx用户及组
worker_processes 1; # 工作进程:数目。根据硬件调整,通常等于CPU数量或者2倍于CPU #error_log logs/error.log; # 错误日志:存放路径
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; # pid(进程标识符):存放路径 events {
worker_connections 1024;
# 每个工作进程的最大连接数量。根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。
# 每个进程允许的最多连接数,nginx最大连接数=worker连接数*worker进程数
} #设定http服务器
http {
include mime.types; # 文件扩展名与文件类型映射表
default_type application/octet-stream; # 默认文件类型 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
# 开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,
# 如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。
# 注意:如果图片显示不正常把这个改成off
#tcp_nopush on; # 激活参数可把httpresponse header和文件的开始放在一个文件里发布,减少网络报文段数量,防止网络阻塞 #keepalive_timeout 0;
# 连接超时时间,单位是秒。
# 客户端到服务器端的连接持续有效时间,当出现对服务器的后继请求时,keepalive-timeout功能可避免建立或重新建立连接
keepalive_timeout 65; #gzip on; # 开启gzip压缩功能 server {
listen 80; # 监听端口
server_name localhost; # 域名可以有多个,用空格隔开 #charset koi8-r; #access_log logs/host.access.log main; location / {
root html; # 站点根目录,即网站程序放的目录
index index.html index.htm; # 首页引导页排序
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443;
# server_name localhost; # ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

  编辑nginx.conf配置文件
    cd /usr/local/nginx/
    vim nginx.conf

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
server_name www.myb.com localhost; location / {
root html;
index index.html index.htm;
}
}
}

  启动nginx
  检查是否有80端口被占用(如若有80端口被启用,首先关掉80端口的相应服务,一般是apach服务)
  netstat -tnl
  netstat -tnl | grep 80    # 没有结果显示,便为正常
  /usr/local/nginx/sbin/nginx    # 启动nginx,此处直接回车即可,没有start
  ps -ef | grep nginx

浏览器输入nginx服务器地址:192.168.168.6

Nginx 虚拟主机配置

 修改nginx.conf配置文件的server段内容如下:

#virtual hosts config 2014/5/18
server {
listen 80;
server_name www.a.com; #access_log logs/host.access.log main; location / {
root html/a;
index index.html index.htm;
} server {
listen 80;
server_name www.b.com; #access_log logs/host.access.log main; location / {
root html/b;
index index.html index.htm;
}
}

  mkdir –p /usr/local/nginx/html/{a,b}
  cd /usr/local/nginx/html/a
  vim index.html # 在目录a和b中分别写入不同的index.html

  /usr/local/nginx/sbin/nginx -t
  /usr/local/nginx/sbin/nginx -s reload # 平滑重启

在windows的hosts文件中添加虚拟主机域名
在浏览器中访问虚拟主机

升级Nginx版本

  cd /softwares

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

  /usr/local/nginx/sbin/nginx -V # 查看升级之前旧版本的configure选项

  编译新版本的Nginx

    tar zxvf nginx-1.6.1.tar.gz
    cd nginx-1.6.1
    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make
    mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old # 备份旧版本的nginx的执行程序
    cp /usr/src/nginx-1.6.1/objs/nginx /usr/local/nginx/sbin/ # 替换旧的Nginx的执行程序
    kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
      # 使nginx的旧版本停止接收请求,由Nginx新版本接替,且老进程处理完所有请求,关闭所有连接后停止服务
    ls /usr/local/nginx/logs/ # 查看nginx日志目录会生成一个nginx.pid.oldbin文件,存放旧版本nginx 的pid号
    /usr/local/nginx/sbin/nginx -t # 检查新版本Nginx是否正常
    /usr/local/nginx/sbin/nginx -s reload # 平滑重启
    /usr/local/nginx/sbin/nginx -v # 查看升级升级后的版本
    netstat -aupt | grep nginx # 查看服务运行状态

reboot操作系统后,重启nginx服务报错:

报错处理:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Centos 7.x 源码编译搭建Nginx的更多相关文章

  1. CentOS 6.5 源码编译搭建LNMP(三台独立主机实现)

    搭建前准备: 1.三台独立主机 nginx:192.168.1.102 php-fpm:192.168.1.105 mysql:192.168.1.103 2.相关软件的源码包 nginx:nginx ...

  2. CentOS 6.5 源码编译搭建LAMP(两台独立主机实现)

    搭建前准备: 1.两台独立主机 httpd:192.168.1.105 php-fpm:192.168.1.105 mariadb:192.168.1.103 2.相关软件的源码包 httpd:htt ...

  3. Centos 7源码编译搭建Nginx

    一.Nginx入门介绍 1. Nginx(engine x):[ˈendʒɪnks] 2. Nginx 是 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版 ...

  4. CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境

    CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...

  5. CentOS 7.4 源码编译安装 Redis

    一.CentOS 7.4  源码编译安装 Redis 1.下载源码并解压 wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar ...

  6. CentOS7 源码编译安装Nginx

    源码编译安装nginx     1.下载nginx源码包(这里以nginx-1.18.0为例) wget http://nginx.org/download/nginx-1.18.0.tar.gz 2 ...

  7. 源码编译安装nginx及设置开机启动项

    1.上传nginx文档:解压到/data目录下,并安装依赖包tar xf nginx-1.20.1.tar.gz -C /data/cd /data/nginx-1.20.1/ && ...

  8. Centos7通过yum跟源码编译安装Nginx

    源码编译安装 http://nginx.org/en/download.html 到官网下载,然后用XFTP上传到root目录 把文件解压出来 tar -zxvf nginx-1.16.0.tar.g ...

  9. centos 6.5源码编译安装subversion 1.8.10

    一.简介 CentOS 6.5的yum源可以安装的SVN客户端版本太低了,1.6.11,所以需要升级到1.8.10,而官网有没有找到1.8.10的安装包,只能选择源码编译安装. 二.安装步骤 参考官网 ...

随机推荐

  1. android studio配置android开发环境

    1.下载安装android-studio-bundle 地址:https://developer.android.com/sdk/index.html 注意:指定android sdk和android ...

  2. Android简单调用相机Camera功能,实现打开照相功能

    在最開始接触Android相机功能之前,先来体验一下Android调用系统照相功能吧 核心代码 Intent intent = new Intent(); //调用照相机 intent.setActi ...

  3. 605B. Lazy Student(codeforces Round 335)

    B. Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. 【特征匹配】SIFT原理之KD树+BBF算法解析

    转载请注明出处:http://blog.csdn.net/luoshixian099/article/details/47606159 继上一篇中已经介绍了SIFT原理与C源代码剖析,最后得到了一系列 ...

  5. [Codeforces 1013B] And

    [题目链接] http://codeforces.com/problemset/problem/1013/B [算法] 不难发现,答案只有0,1,2,-1,共4种取值 分类讨论即可,计算时可以使用ST ...

  6. DCloud-MUI:代码块

    ylbtech-DCloud-MUI:代码块 1.返回顶部 1. 怎么用? html      此底色代表最小触发字符      此底色代表非必要完整触发字符 *需HBuilder7.1+,或者下载m ...

  7. Swift备忘录

    Swift 备忘录 2015-4 一.简介 1.Swift 语言由苹果公司在2010年7月开始设计,在 2014 年6月推出,在 2015 年 12 月 3 日开源 2.特点(官方): (1)苹果宣称 ...

  8. android有用代码片段

    一.  获取系统版本号: [java] view plaincopy PackageInfo info = this.getPackageManager().getPackageInfo(this.g ...

  9. md5的用处

    MD5保存摘要及指纹信息 md5的用处: 1.保存用户密码2.校验数据的完整性

  10. 玩游戏(dfs)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2566 #include <stdio.h ...