一、介绍

  Nginx是一款轻量级Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。本文先整理web服务器内容。

二、环境及软件版本

  1. 操作系统:CentOS 6.6 X64
  2. Nginx版本:nginx-1.10.2.tar.gz

三、安装

  •  下载nginx安装包
[root@LFTp-Svn01 soft]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
--2016-11-14 17:30:20-- http://nginx.org/download/nginx-1.10.2.tar.gz
Connecting to 10.112.11.12:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 910812 (889K) [application/octet-stream]
Saving to: “nginx-1.10.2.tar.gz” 100%[===================================================================================================================>] 910,812 627K/s in 1.4s 2016-11-14 17:30:22 (627 KB/s) - “nginx-1.10.2.tar.gz” saved [910812/910812]
  •  运行环境安装
[root@LFTp-Svn01 soft]# yum -y install pcre pcre-devel openssl openssl-devel gcc
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Package pcre-7.8-7.el6.x86_64 already installed and latest version
Package pcre-devel-7.8-7.el6.x86_64 already installed and latest version
Package openssl-1.0.1e-42.el6_7.4.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-42.el6_7.4.x86_64 already installed and latest version
Package gcc-4.4.7-16.el6.x86_64 already installed and latest version
Nothing to do
  •  解压编译Nginx
[root@LFTp-Svn01 soft]# tar -xf nginx-1.10.2.tar.gz
[root@LFTp-Svn01 soft]# cd nginx-1.10.2
[root@LFTp-Svn01 nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
.................................................................................................
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
备注:
--prefix #指定安装目录
--with-http_stub_status_module #stub_status监控模块
--with-http_ssl_module #ssl模块
--with-http_gzip_static_module #压缩传输模块
--with-pcre #pcre模块,nginx强依赖
  •  安装Nginx
[root@LFTp-Svn01 nginx-1.10.2]# make && make install
...................................................................................
cp conf/fastcgi_params \
'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/soft/nginx-1.10.2'
[root@LFTp-Svn01 nginx-1.10.2]# echo $?
0 #测试安装没问题
  •  配置Nginx启动脚本
将以下脚本内容命名nginx文件,放置/etc/init.d/下,并赋予执行权限
=========================================
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid RETVAL=0
prog="nginx" # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions.
start() { if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL } # Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
} # reload nginx service functions.
reload() { echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo } # See how we were called.
case "$1" in
start)
start
;; stop)
stop
;; reload)
reload
;; restart)
stop
start
;; status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac exit $RETVAL
  •  Nginx默认配置文件和虚拟机主机配置:
user  nobody;
worker_processes 1;
worker_rlimit_nofile 65535; #error_log logs/error.log;
pid logs/nginx.pid; events {
worker_connections 65535;
use epoll;
} 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" "$request_time"'; #access_log logs/access.log main; sendfile on;
tcp_nopush on;
keepalive_timeout 65;
client_max_body_size 64M;
gzip on; #开启gzip
gzip_min_length 1024;
gzip_buffers 4 8k;
gzip_types application/x-javascript text/css application/xml; fastcgi_connect_timeout 300;
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_temp_file_write_size 64k; #安全检查需要禁止缓存
#expires 0;
expires 1d;
#add_header Pragma no-cache;
#add_header Cache-Control no-cache;
#add_header Cache-Control no-store;
#add_header Cache-Control must-revalidate; #安全需要禁止iFrame,防止iFrame嵌入
add_header X-Frame-Options SAMEORIGIN; add_header via $server_name:$server_port(php01);
include vhost/*.conf;
}

nginx.conf

server {
listen 80 ;
server_name nginx.lain.xyz ;
access_log logs/access.nginx.log main;
error_log logs/error.nginx.log; location ^~ /lain/ {
root /home/www/;
} location / {
root /home/www/lain/webroot;
index index.php index.html index.htm;
rewrite ^(.*).do$ $1.php last;
}
location ~ \.php$ {
fastcgi_pass unix:/dev/shm/php-fpm.sock;
root /home/www/lain/webroot;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/www/ehome_pay_op/webroot/$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
root /home/www/lain/webroot;
#expires 30d;
log_not_found off; #禁用not found 报错
}
error_page 403 404 /40x.html;
location = /40x.html {
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

nginx.lain.xyz

Linux系统运维之Web服务器Nginx安装的更多相关文章

  1. Linux系统运维笔记(四),CentOS 6.4安装Nginx

    Linux系统运维笔记(四),CentOS 6.4安装Nginx 1,安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool op ...

  2. Linux系统运维笔记(五),CentOS 6.4安装java程序

    Linux系统运维笔记(五),CentOS 6.4安装java程序 用eclipse编译通的java程序,现需要实施到服务器.实施步骤: 一,导出程序成jar包. 1,在主类编辑界面点右健,选  ru ...

  3. Linux系统运维笔记(四),CentOS 6.4安装 MongoDB

    Linux系统运维笔记(四),CentOS 6.4安装 MongoDB 1,下载 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6 ...

  4. Linux系统运维笔记(三),设置IP和DNS

    Linux系统运维笔记(三),设置IP和DNS 手工配置静态的IP地址 也就是手工配置IP地址.子网掩码.网关和DNS. vi /etc/sysconfig/network-scripts/ifcfg ...

  5. Linux系统运维笔记(一),查看系统版本和设置系统时间

    Linux系统运维笔记 查看系统版本和设置系统时间 查看系统版本 lsb_release -a (适用于所有的linux,包括Redhat.SuSE.Debian等发行版,但是在debian下要安装l ...

  6. Linux系统运维笔记(6),CentOS 7.6双网卡路由配置

    Linux系统运维笔记(6),CentOS 7.6双网卡路由配置. 一,先确认系统版本: [root@localhost ~]# cat /etc/redhat-releaseCentOS Linux ...

  7. Linux系统运维相关的面试题 (问答题)

    这里给大家整理了一些Linux系统运维相关的面试题,有些问题没有标准答案,希望要去参加Linux运维面试的朋友,可以先思考下这些问题.   一.Linux操作系统知识 1.常见的Linux发行版本都有 ...

  8. 7.学完linux系统运维到底可以做什么?

    linux运维到底可以做什么?(略有改动原文.排版) 运维,很容易从字面理解为运营.维护. 很多朋友认为,在互联网公司中linux系统运维的工作就是安装系统,部署服务.处理紧急故障,为公司里的开发人员 ...

  9. Linux系统运维笔记(二),Linux文件编辑命令

    Linux系统运维笔记 Linux文件编辑命令 首先我们使用命令 vi filename 打开一个文件,这个时候进入到的是命令模式 接下来我们按i,然后键盘随便输入写内容. 然后按ESC重新进入到命令 ...

  10. Linux系统运维工程该具备哪些素质

    记得在上高中时,物理老师总是会对我们一句话:"学习是件苦差事."工作后发现,其实做运维也是件苦差事.最为一名运维工程师,深知这一行的艰辛,但和IT行业其他职务一样,那就是付出的越多 ...

随机推荐

  1. 最新版本 Stable Diffusion 开源 AI 绘画工具之使用篇

    目录 界面参数 采样器 文生图(txt2img) 图生图(img2img) 模型下载 界面参数 在使用 Stable Diffusion 开源 AI 绘画之前,需要了解一下绘画的界面和一些参数的意义 ...

  2. 升级二进制kubernetes集群

    升级二进制kubernetes集群 背景介绍 最近由于时间不足,暂时无法对小版本更新第一时间出新的文档.若需要升级集群版本,可以参考此文档进行操作,每个节点一个一个地更新.大版本更新请各位持续关注我的 ...

  3. k8s集群进行删除并添加node节点

    在已建立好的k8s集群中删除节点后,进行添加新的节点,可参考用于添加全新node节点,若新的node需要安装docker和k8s基础组件. 建立集群可以参考曾经的文章:CentOS8 搭建Kubern ...

  4. [网络]公共网络安全漏洞库: CVE / CNCVE

    本文博主的经历与该博文处理绿盟科技安全评估的系统漏洞 - 博客园的经历相同: 处理[第三方网络安全公司]给[公司产品]的[客户的服务器]扫描后生成的[安全漏洞报告]. 1 前言 以网络安全行业中最大的 ...

  5. 【FINALE】NOIP2022 退役记 || THE END.

    我的停课生活相册 - password:1007 目录 Day -4 Day -2 Day -1 Day 1 2022/11/26 NOIP 2022 OI 浅忆录 Day -4 好冷啊.有了那么点冬 ...

  6. mysql中innodb_open_files限制导致数据库异常重启

    问题描述:收到监控软件告警,提示数据库发生重启,进去查看,截止到6/27 10:00 之前,作为主节点的orch1先重启,然后故障转移到orch2和orch3节点上.在持续到6/27 9:00 左右, ...

  7. Go For Web:Golang http 包详解(源码剖析)

    前言: 本文作为解决如何通过 Golang 来编写 Web 应用这个问题的前瞻,对 Golang 中的 Web 基础部分进行一个简单的介绍.目前 Go 拥有成熟的 Http 处理包,所以我们去编写一个 ...

  8. springCloud Alibaba服务的注册与发现之eureka搭建

    1.创建eureka微服务模块.导入maven依赖. <dependency> <groupId>org.springframework.cloud</groupId&g ...

  9. [C++基础入门] 2、数据类型

    文章目录 2 数据类型 2.1 整型 2.2 sizeof关键字 2.3 实型(浮点型) 2.4 字符型 2.5 转义字符 2.6 字符串型 2.7 布尔类型 bool 2.8 数据的输入 2 数据类 ...

  10. 2022年5月5日模拟赛题解与总结(ABC237)

    总结 初一第一,竞赛班第二 还可以,为了照顾提高班来的四个同学放了四个水题,可惜他们做的不是很理想,希望他们下次可以获得满意的成绩 这次做的其实是 AtCoder ABC237 A.Not Overf ...