centos手动编译安装nginx

简介: centos nginx源码安装

1,到官网下载nginx
http://nginx.org/download/nginx-1.10.3.tar.gz
wget http://nginx.org/download/nginx-1.10.3.tar.gz
image
2,安装必要的组件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
image

3,安装pcre,这里用的是8.42(用于rewrite模块)
到官网下载:https://nchc.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip

image
解压unzip pcre-8.42.zip

image

cd pcre-8.42/
./configure && make && make install
image
pcre-8.42安装完毕。
4 安装nginx
解压nginx,切到nginx源码目录
tar xf nginx-1.10.3.tar.gz && cd nginx-1.10.3
image

编译安装nginx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.42 && make && make install
image
安装完毕!
5,开启和配置nginx(现在安装的nginx是软件自带的配置)
我这里有配置好的nginx.conf

user  www;
worker_processes  auto;


error_log  /usr/local/nginx/logs/error.log  warn;
pid        /usr/local/nginx/nginx.pid;

events {
    use epoll ;
    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"';
    server_tokens off;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    client_max_body_size 20m;
    add_header X-Frame-Options SAMEORIGIN ;

    fastcgi_buffers 2 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 512k;
    
    server {
    listen 80 default_server;
    server_name _;
    return 444;  
 }
  
    include vhost/*.conf  ;
}

image
替换原始的nginx.conf,添加www用户
6,启动nginx
/usr/local/nginx/sbin/nginx -t(测试语法)
image
/usr/local/nginx/sbin/nginx(启动)
ps -ef|grep nginx(查看进程)
image
7,加入系统变量
[root@localhost nginx-1.10.3]# echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile
[root@localhost nginx-1.10.3]# . /etc/profile
image
8,设置开机启动
启动脚本如下

#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

# Author:   licess
# website:  http://lnmp.org

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid

case "$1" in
    start)
        echo -n "Starting $NAME... "

        if netstat -tnpl | grep -q nginx;then
            echo "$NAME (pid `pidof $NAME`) already running."
            exit 1
        fi

        $NGINX_BIN -c $CONFIGFILE

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    stop)
        echo -n "Stoping $NAME... "

        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi

        $NGINX_BIN -s stop

        if [ "$?" != 0 ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
        ;;

    status)
        if netstat -tnpl | grep -q nginx; then
            PID=`pidof nginx`
            echo "$NAME (pid $PID) is running..."
        else
            echo "$NAME is stopped"
            exit 0
        fi
        ;;

    force-quit)
        echo -n "Terminating $NAME... "

        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi

        kill `pidof $NAME`

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    reload)
        echo -n "Reload service $NAME... "

        if netstat -tnpl | grep -q nginx; then
            $NGINX_BIN -s reload
            echo " done"
        else
            echo "$NAME is not running, can't reload."
            exit 1
        fi
        ;;

    configtest)
        echo -n "Test $NAME configure files... "

        $NGINX_BIN -t
        ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
        ;;

esac

保存为nginx,加入系统服务
image
nginx安装完毕!
我的阿里云1000元代金券地址:
https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=3ow2kbko

目录
相关文章
|
10天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
14 0
|
1月前
|
Linux 开发工具 C语言
Centos8下编译安装最新版ffmpeg解决方案(含Centos8换源阿里云)
Centos8下编译安装最新版ffmpeg解决方案(含Centos8换源阿里云)
144 3
|
3月前
|
应用服务中间件 Linux 网络安全
centos7 下离线安装gcc g++ nginx,并配置nginx进行网络流转发
centos7 下离线安装gcc g++ nginx,并配置nginx进行网络流转发
104 0
|
2月前
|
Linux 应用服务中间件 网络安全
CentOS7搭建本地离线局域网yum源(Httpd/Nginx+yum)
CentOS7搭建本地离线局域网yum源(Httpd/Nginx+yum)
293 0
|
2月前
|
缓存 负载均衡 应用服务中间件
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
70 1
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
|
10天前
|
网络协议 应用服务中间件 Linux
centos7 Nginx Log日志统计分析 常用命令
centos7 Nginx Log日志统计分析 常用命令
23 2
|
2月前
|
存储 Linux 应用服务中间件
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
120 1
|
3月前
|
Linux C语言
centos 7 下使用高版本gcc编译安装
centos 7 下使用高版本gcc编译安装
114 0
|
3月前
|
负载均衡 NoSQL 应用服务中间件
Nginx编译安装及配置文件详解
Nginx编译安装及配置文件详解
|
3月前
|
安全 应用服务中间件 Linux
百度搜索:蓝易云【CentOS7使用Nginx、Supervisor部署Go/Golang服务教程】
这些是在CentOS 7 x64上使用Nginx和Supervisor部署Go/Golang服务的基本步骤。根据您的需求和具体环境,可能还需要进行其他配置和调整。请确保在进行任何与网络连接和安全相关的操作之前,详细了解您的网络环境和安全需求,并采取适当的安全措施。
61 0