yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel创建一个文件夹cd /usr/localmkdir nginxNginx cache purge模块(可选)# wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz#...

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
创建一个文件夹 cd /usr/local mkdir nginx
Nginx cache purge模块(可选)
# wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz #tar -xzf ngx_cache_purge-1.3.tar.gz
编译安装
# tar -xzvf nginx-1.0.6.tar.gz
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../ngx_cache_purge-1.3
--prefix=/usr/local/nginx-1.0.6 # 安装路径
--with-http_stub_status_module # 启用nginx状态模块
--with-http_ssl_module # 启用SSL模块
--with-http_realip_module # 启用realip模块(将用户IP转发给后端服务器)
--add-module=../ngx_cache_purge-1.3 # 添加缓存清除扩展模块
# make
# make install
内核参数优化
# vi sysctl.conf 增加以下配置
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 1800
net.ipv4.ip_conntrack_max = 16777216 # 如果使用默认参数,容易出现网络丢包
net.ipv4.netfilter.ip_conntrack_max = 16777216# 如果使用默认参数,容易出现网络丢包
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries =
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024 65535
配置生效
# sysctl –p
修改iptables启动脚本,在star()函数里面加上
# vi /etc/init.d/iptables
/sbin/sysctl -p
修改nginx配置文件:
# vi nginx.conf
user nobody nobody; # 运行nginx的所属组和所有者
worker_processes 2; # 开启两个nginx工作进程,一般几个CPU核心就写几
error_log logs/error.log notice; # 错误日志路径
pid logs/nginx.pid; # pid路径
events {
worker_connections 1024; # 一个进程能同时处理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;
keepalive_timeout 65; # keepalive超时时间
# 开始配置一个域名,一个server配置段一般对应一个域名
server {
listen 80; #
# 在本机所有ip上监听80,也可以写为192.168.1.202:80,这样的话,就只监听192.168.1.202上的80口
server_name www.yang.com; # 域名
root /www/html/yang; # 站点根目录(程序目录)
index index.html index.htm; # 索引文件
location / { # 可以有多个location
root /www/html/yang; # 站点根目录(程序目录)
}
error_page 500 502 503 504 /50x.html;
# 定义错误页面,如果是500错误,则把站点根目录下的50x.html返回给用户
location = /50x.html {
root /www/html/yang
}
}
# 开始配置站点bbs.yang.com
server {
listen 80;
server_name bbs.yang.com;
root /www/html/bbsyang;
index index.html index.htm; # 索引文件
location / {
root /www/html/bbsyang;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /www/html/bbsyang;
}
}
}
Nginx启动关闭
# /usr/local/nginx-1.0.6/sbin/nginx //启动nginx
# /usr/local/nginx-1.0.6/sbin/nginx –t //测试nginx配置文件的准确性
# /usr/local/nginx-1.0.6/sbin/nginx –s reload //重载nginx
# /usr/local/nginx-1.0.6/sbin/nginx –s stop //关闭nginx
测试
创建测试站点
# mkdir –p /www/html/yang
# mkdir –p /www/html/bbsyang
# echo "www.yang.com" > /www/html/yang/index.html
# echo "bbs.yang.com" > /www/html/bbsyang/index.html
启动nginx
# /usr/local/nginx-1.0.6/sbin/nginx –t //看到ok和successful,说明配置文件没问题
nginx: the configuration file /usr/local/ nginx-1.0.6/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/ nginx-1.0.6/conf/nginx.conf test is successful
# /usr/local/nginx-1.0.6/sbin/nginx
绑定hosts,测试
把两个域名指向192.168.1.202
192.168.1.202 www.yang.com
192.168.1.202 bbs.yang.com
打开www.yang.com如下图:
nginx
打开bbs.yang.com,如下图:
nginx
本文标题为:centos7.4下源码安装nginx并附shell安装脚本


- nginx中封禁ip和允许内网ip访问的实现示例 2022-09-23
- 利用Docker 运行 python 简单程序 2022-10-16
- 教你在docker 中搭建 PHP8 + Apache 环境的过程 2022-10-06
- 解决:apache24 安装后闪退和配置端口映射和连接超时设置 2023-09-11
- IIS搭建ftp服务器的详细教程 2022-11-15
- CentOS_mini下安装docker 之 安装docker CE 2023-09-23
- 【转载】CentOS安装Tomcat 2023-09-24
- KVM虚拟化Linux Bridge环境部署的方法步骤 2023-07-11
- 阿里云ECS排查CPU数据分析 2022-10-06
- CentOS7安装GlusterFS集群的全过程 2022-10-10