1.wget http://nginx.org/download/nginx-1.14.0.tar.gz
2.tar zxvf nginx-1.14.0.tar.gz
查看源码文件:/nginx/src

cd /nginx
编译安装: ./configure --prefix=/usr/local/nginx #/usr/local/nginx 指定安装 目录
实例如下:

安装成功如下:

make #编译
成功后,截图如下:

已安装完成,安装文件路径为:

conf下为配置 文件。
html下为默认页。 html下的index为欢迎页。
logs下为日志文件。
sbin下为可执行文件。
查看版本:

启动:
/usr/local/nginx/sbin/nginx (或者,进入到sbin下,./nginx)

杀死进程,停止nginx的服务。
pkill nginx (或者killall nginx ,若没有安装killall,则yum安装psmisc)

/usr/local/nginx/sbin/nginx -t #检查配置文件语法错误。
若出现ok,或者successful,则没有错误。
/usr/local/nginx/sbin/nginx -s reload #重载配置。

设置nginx开机启动:
chkconfig --add nginx
chkconfig nginx on 设置为开机启动。

源码安装的卸载:只需要删除/usr/local/nginx文件,(./configure --prefix=/usr/local/nginx)这里目录是什么,则删除什么。

nginx 启动脚本
vim /etc/init.d/nginx //复制如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx )
完成之后,chmod 755 /etc/init.d/nginx

#!/bin/bash
.# chkconfig: - 30 21
.# description: http service.
.# Source Function Library
. /etc/init.d/functions
.# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"

start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}

stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}

reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}

restart()
{
stop
start
}

configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac

exit $RETVAL

配置文件
cd /usr/local/nginx/conf/; mv nginx.conf nginx.conf.bak

vim nginx.conf //写入如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf)
user nobody nobody; #启动服务是哪个用户
worker_processes 2; #定义子进程有几个,
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200; #nginx 最多可以打开多少个文件

events
{
use epoll;
worker_connections 6000; #进程最多有多少连接
}

http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server #每个server对应一个虚拟主机
{
listen 80; #监听80端口
server_name localhost; # server_name就是域名
index index.html index.htm index.php;
root /usr/local/nginx/html; #网站根目录所在路径

    location ~ \.php$                #解析php{include fastcgi_params;fastcgi_pass unix:/tmp/php-fcgi.sock;            #指定php服务的监听端口,或者sock文件,或者可以写成127.0.0.1:9000#fastcgi_pass  127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;}
}

}

/usr/local/nginx/sbin/nginx -t #检查是否存在语法错误
/etc/init.d/nginx start #启动服务
ps aux | grep nginx
netstat -lntp |grep 80
curl localhost

转载于:https://blog.51cto.com/13451715/2322349

Linux -nginx-源码安装相关推荐

  1. linux python源码安装,linux上源码安装python

    以下例子基于python 2.7.9,其他版本同理.# 1.下载python# wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tg ...

  2. Nginx源码安装及调优配置

    由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优化 [ ...

  3. glib 2.0 arm linux,glib源码安装使用方法

    glib库是GTK+和GNOME工程的基础底层核心程序库,是一个综合用途的实用的轻量级的C程序库,它提供C语言的常用的数据结构的定义.相关的处理函数,有趣而实用的宏,可移植的封装和一些运行时机能,如事 ...

  4. Linux下源码安装CodeBlocks

    Linux下源码安装CodeBlocks qianghaohao(CodingNutter) 一. 安装平台说明: CentOs6.4-i686  gcc-4.4.7 二. 下载最新源码: http: ...

  5. linux中源码安装node

    Linux上安装Node.js 直接使用已经编译好的包 node 官网已经把linux 下载版本更改为已经编译好的版本了,我们可以直接下载解压后使用: wget https://nodejs.org/ ...

  6. 【 ViSP(1) - Linux Melodic 源码安装 ViSP】

    Linux Melodic 源码安装 ViSP Linux Melodic 源码安装 ViSP 1. ViSP 简介 2. 源码安装 2.1 Required packages 需要的安装包 2.2 ...

  7. 5.3.3.tat.gz php_一步步在LINUX中源码安装PHP运行平台

    一步步在LINUX中源码安装PHP运行平台 一步步在LINUX中源码安装PHP运行平台 本人是LINUX新手, 今天我们要学习一下如何在LINUX环境下安装PHP运行环境 目标:在LINUX环境下源码 ...

  8. Nginx源码安装及应用

    一:Nginx简介: Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器.在高连接并发的情况下,Nginx是Apache服务器不错的替代品. Nginx作 ...

  9. nginx源码安装教程(CentOS)

    1.说明 官方源码安装说明:http://nginx.org/en/docs/configure.html 源码包下载地址:http://nginx.org/en/download.html 版本说明 ...

  10. linux编译安装的好处,Linux学习—源码安装

    源码安装--可以按照自己的需求安装,这是源码安装的好处,而二进制安装无法选择 大部分的源码安装步骤大致相同,具体细节可以参考解压缩之后的README和INSTALL README: 介绍了软件包的功能 ...

最新文章

  1. Day1 - Python基础1作业【编写登陆接口】
  2. RANSAC算法做直线拟合
  3. kibana操作elasticsearch:match匹配查询(最小匹配参数查询)
  4. linux遍历目录源代码
  5. MFC图像点运算之灰度线性变化、灰度非线性变化、阈值化和均衡化处理
  6. Java 工具类 - MD5Util
  7. 两种方法上传本地文件到github
  8. ECSHOP的订单状态在数据库中的表现(order_status, shipping_status, pay_status)
  9. 4. COM编程——IUnknown介绍
  10. 44. Wildcard Matching (String; DP, Back-Track)
  11. react native+typescript创建移动端项目-(慕课网喜马拉雅项目笔记)-(一,项目的初始化配置)
  12. 推荐系统实践:基于数据集MovieLens构造简单推荐系统
  13. jact变频器故障代码_高淳JACT变频器,艾克特变频器ERR20编码器故障维修烟台市...
  14. 计算机科学期刊介绍--各种杂志投稿方式与评价
  15. 手机无法打开html文件夹,手机网站在电脑上无法打开的解决办法
  16. 货币汇率换算器隐私协议
  17. 嵌入式开发基本环境搭建---ubuntu
  18. 梦亚网络验证开源源码
  19. python 学习总结2 多进程与协程
  20. 为什么结婚戒指要带在无名指上?

热门文章

  1. 机器翻译:谷歌翻译是如何对几乎所有语言进行翻译的?
  2. 我们真的需要深度图神经网络吗?
  3. 「技术综述」一文道尽传统图像降噪方法
  4. 【谷歌推网页爬虫新标准,开源robots.txt解析器】
  5. 「AI初识境」近20年深度学习在图像领域的重要进展节点
  6. 港片中十个难以超越的经典人物形象
  7. 深度学习已入末路,谁能引领下一代AI?
  8. 一流的管理者,都具备非凡的洞察力
  9. “新一代城市大脑建设与发展“专家研讨会
  10. 亚马逊:从零售商向科技公司的质变