安装nginx的步骤:
1).root用户登录
2).yum info nginx
找不到nginx的安装包
3).rpm -ivh https://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
(要能够连接外网)
4).yum repolist 发现yum源中,多了个nginx cd /etc/yum.repo.d
5).安装nginx:yum -y install nginx ##(要能够连接外网)
6).service nginx start
ps:查看nginx安装目录 whereis nginx
7).查看http://192.168.209.21 如果可以看到nginx的页面就表示你已经配置ok了
8).配置下nginx
cd /etc/nginx/
vi /etc/nginx/nginx.conf
配置说明
===============================================================================================================
user root; #nginx的运行账号(rpm安装时会自动创建这个账号),也可以写成user nginx nginx表示用户和组
worker_processes 10; #工作进程数(worker),一般等于cpu内核数或者两倍
error_log /var/log/nginx/error.log warn; #错误日志存放目录
pid /var/run/nginx.pid; #进程pid存放位置
events {
worker_connections 1024; #单个后台worker process进程的最大并发链接数
}
http {
include /etc/nginx/mime.types; #引入文件扩展名与类型映射表
default_type application/octet-stream; #默认文件类型
#log_format 日志格式 main:格式名称 ;日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format my_log_format '$remote_addr^A$msec^A$http_host^A$request_uri';##自定义日志格式
sendfile on; #开启高效传输模式
#tcp_nopush on; #激活tcp_nopush参数可以允许把httpresponse header和文件的开始放在一个文件里发布,积极的作用是减少网络报文段的数量
keepalive_timeout 65; #连接超时时间,单位是秒
#gzip on; #开启gzip压缩功能
#include /etc/nginx/conf.d/*.conf; #引入配置文件,默认的首页就是在这里引入的,我们要把这行注释掉
server {
listen 80; #监听端口
server_name www.teachercao.com; #使用哪儿个域名访问
index index.html; #首页面
root /data/www/web; #资源根目录
location ~ / {
#用access_log指定日志文件存放路径;路径 /var/log/nginx/access.log; my_log_format:(自定义日志名称,和log_format设置的名称一致)
access_log /var/log/nginx/access.log my_log_format;
}
}
}
===============================================================================================================
创建请求的目录 mkdir -p /data/www/web
echo "<p>this is nginx</p>" >>/data/www/web/index.html
(也可以使用 vi /data/www/web/index.html)
关闭防火墙:linux自带的防火墙 selinux
vi /etc/selinux/config
修改SELINUX=disabled
reboot重启机器(一定要重启机器)
service nginx start
此时web页面就可以访问了。(IE)
本文详细介绍了在CentOS6上安装Nginx的步骤,包括下载安装包,配置yum源,安装nginx,启动服务,配置nginx.conf文件,并提供了相关目录和配置示例。最后,通过创建web目录并测试页面访问来验证Nginx配置的成功。
2359

被折叠的 条评论
为什么被折叠?



