Operation and maintenance
  • 目录
  • linux 历史
    • Linux网卡配置
    • linux互相登陆
  • 文件目录管理
    • linux目录结构
    • 文件的基本信息
    • linux别名alias
    • 环境变量
    • linux终端相关快捷键
    • linux文件和目录添加删除
    • linux文件查看命令
    • linux文件目录权限
    • linux文件特殊权限
    • 链接文件
    • linux下文件查找
    • linux和window文件互传
    • linux文件压缩和打包
    • vim工具集
  • 用户和组管理
    • 用户组和用户管理
    • 修改组和用户
    • 用户切换
    • 禁止root远程登陆
  • linux磁盘管理
    • 磁盘分区
    • 格式化磁盘
    • 分区挂载
    • 手动添加swap分区
    • lvm基础
  • linux软件安装和卸载
    • rpm工具
    • yum工具
    • 源码安装包
  • 日常运维
    • 监控磁盘IO
    • 查看网络状态
    • linux抓包
    • linux网络相关
    • Linux防火墙-netfilter
    • linux任务计划
    • linux系统服务管理
    • linux同步工具rsync
    • linux系统日志和screen
  • LAMP架构
    • 安装mysql
    • 免编译安装mariadb
    • 安装apache
    • 安装php5
    • 安装php7
    • apache 配置虚拟主机
    • apache 用户认证
    • apache 域名跳转
    • apache 访问日志
    • apache 不记录文件日志
    • apache 配置静态元素过期时间
    • apache 配置防盗链
    • apache 访问控制
    • apache 禁止解析php文件
    • apache 禁止user_agent
    • php 配置文件
    • php 动态扩展模块安装
  • LNMP架构
    • 安装mariadb
    • 安装php
    • 安装nginx
    • nginx 默认虚拟主机
    • nginx 用户认证
    • nginx 域名重定向
    • nginx 访问日志
    • nginx 日志切割
    • nginx不记录指定文件类型日志
    • nginx 静态文件和过期时间
    • nginx 防盗链
    • nginx 访问控制
    • nginx 解析php
    • nginx 代理
    • nginx 负载均衡
    • nginx 支持https
  • MySQL集合
    • 更改root密码
    • mysql 常用操作
    • mysql 常用sql
    • mysql 数据备份
    • mysql 主从配置
  • linux常用服务
    • nfs 服务搭建
    • CentOS7 搭建snmp服务
    • ftp 服务搭建
    • samba 服务搭建
    • Squid 服务搭建
    • Tomcat 服务搭建
    • resin 搭建
    • dns 服务搭建
    • iscsi 服务搭建
  • linux开发语言环境
    • python 开发环境
    • golang 开发环境
  • linux集群架构
    • linux 高可用
    • linux 负载均衡
  • linux监控平台
    • zabbix 监控平台(上)
  • shell集合
  • NoSql
    • memcached (上)
    • memcached(下)
    • redis(上)
    • redis(中)
    • redis(下)
    • mongodb(上)
    • mongodb(中)
    • mongodb(下)
  • 代码管理工具
    • 代码管理工具 svn
    • 代码管理工具 git
    • 搭建git私有仓库
    • 安装配置gitlab
  • docker 入门
    • docker 安装
    • docker 镜像管理
    • docker 容器管理
    • docker 仓库管理
    • docker 共享目录
    • docker 数据备份和恢复
    • docker 网络管理
    • docker 使用dockerfile
    • docker compose
  • 自动化运维
    • saltstack 安装
    • saltstack 配置认证
    • saltstack 远程执行命令
    • saltstack grains
    • saltstack pillar
    • saltstack 实战:安装配置httpd
    • saltstack 实战:配置管理文件
    • saltstack 实战:配置管理远程命令
    • saltstack 实战:配置管理任务计划
    • saltstack salt-ssh工具
    • ansible 安装
    • ansible 远程命令
    • ansible 远程目录拷贝
    • ansible 任务计划
    • ansible 远程rpm/服务管理
    • ansible playbook 详解
    • ansible playbook 实战:安装nginx
  • linux虚拟化
    • KVM介绍
    • 安装KVM
    • 虚拟机管理
    • 克隆虚拟机
    • 快照管理
    • 磁盘扩容
    • 调整虚拟机配置
    • 迁移虚拟机
  • 错误排查
    • linux启动挂在不上sysroot问题
由 GitBook 提供支持
在本页

这有帮助吗?

  1. LNMP架构

安装nginx

上一页安装php下一页nginx 默认虚拟主机

最后更新于4年前

这有帮助吗?

Nginx官网 nginx.org,最新版1.13,最新稳定版1.12

Nginx应用场景:web服务、反向代理、负载均衡 Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并 Nginx核心+lua相关的组件和模块组成了一个支持lua的高性能web容器openresty,

参考

下载

cd /usr/local/src
wget http://nginx.org/download/nginx-1.15.2.tar.gz

解压

tar zxf nginx-1.15.2.tar.gz

编译安装

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

make && make install

启动脚本

vim /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

保存后,更改权限

chmod 755 /etc/init.d/nginx
chkconfig --add nginx

如果想开机启动,请执行

chkconfig nginx on

配置文件

cd /usr/local/nginx/conf/; mv nginx.conf nginx.conf.bak
vim 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;

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
    {
        listen 80;
        server_name localhost;
        index index.html index.htm index.php;
        root /tmp/1233;    # 需要一个虚拟主机防止网络域名指向
    }
}

启动服务

service nginx start
ps aux | grep nginx

测试php

vim /usr/local/nginx/html/index.php

<?php
  echo "Hello World";
?>
http://jinnianshilongnian.iteye.com/blog/2280928