博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS下nginx简单安装
阅读量:7282 次
发布时间:2019-06-30

本文共 3529 字,大约阅读时间需要 11 分钟。

说明:

环境

系统:Centos 6软件包:nginx-1.2.4

配置系统yum源

#/etc/yum.repos.d/#rm -rf ./*vi localhost.repos.d[yumyuan] name=CentOS-$releasever - Media                                       #自定义名称  baseurl=file:///mnt/cdrom/                                            #本地光盘挂载路径gpgcheck=0                                                            #检查GPG-KEY,0为不检查,1为检查  enabled=1                                                             #启用yum源,0为不启用,1为启用

2: 安装步骤

因为nginx模块需要第三方库的支持,需要安装下列库.
安装gcc编译器及相关工具

#yum -y install gcc gcc-c++ autoconf automake make

安装相关依赖的模块

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

创建nginx系统账户:

由于nginx是系统服务,运行此服务需要系统账户。

# groupadd nginx# useradd -r -g nginx -s /sbin/nologin -M nginx软件源码包存放位置:/opt/#cd /opt/# tar -zxvf nginx-1.2.4.tar#cd nginx-1.2.4#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module  --with-http_ssl_module    //通过编译源码的方式进行安装 #make#make install          启动Nginx#启动nginx#/usr/local/nginx/sbin/nginx -t显示以下信息为正确的the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful#/usr/local/nginx/sbin/nginx启动成功后,查看nginx进程信息: # ps -ef | grep nginx ,看是否存在nginx的进程来确认是否成功启动。1.在配置nginx 时提示如下错误时:#/usr/local/nginx/sbin/nginx -tnginx: [emerg] getpwnam(“nginx”) failed

解决方案

在nginx.conf中 把user nobody的注释去掉既可

2.重启nginx后丢失nginx.pid问题解决

/usr/local/nigix/sbin/nginx -c /usr/local/nigix/conf/nginx.conf

重启动nginx

#/usr/local/nginx/sbin/nginx -s reload

测试

同时记得检查centos防火墙设置,是否开启了相应端口,可使用setup命令来设置防火墙、dns、网络等信息。如果默认的配置文件未做任何改动,使用浏览器直接访问nginx server,会出现提示:Welcome to Nginx  

nginx.conf文件详解:

########nginx全局配置,将影响其他所有设置####################################user  nobody;                          # worker进程运行用户以及用户组worker_processes  2;                    #启动进程,通常设置成和cpu的数量相等error_log  /var/log/nginx/error.log;    ##全局错误日志及PID文件pid        /var/run/nginx.pid;          #指定进程id的存储文件位置#工作模式及连接数上限events {     use   epoll;                #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能     worker_connections  1024;    #单个后台worker process进程的最大并发链接数    #multi_accept on; }#对http服务器进行配置http {       #设定mime类型,类型由mime.type文件定义       include       /etc/nginx/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  /var/log/nginx/access.log main      #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,      #必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.       sendfile        on;       #tcp_nopush     on;        #连接超时时间        #keepalive_timeout  0;         keepalive_timeout  65;         tcp_nodelay        on;        #开启gzip压缩        gzip  on;        gzip_disable "MSIE [1-6]\.(?!.*SV1)";#主机设置       server {       #侦听80端口            listen       80;            #定义使用www.xx.com访问            server_name  www.xx.com;            #设定本虚拟主机的访问日志            access_log  logs/www.xx.com.access.log  main;       #默认请求(url匹配设置)        location / {               root   /usr/local/nginx/html;      #定义服务器的默认网站根目录位置              index index.php index.html index.htm;   #定义首页索引文件的名称                    }                 # 定义错误提示页面        error_page   500 502 503 504 /50x.html;             location = /50x.html {             root   /usr/local/nginx/html;             }       } #server }

   

转载地址:http://vnkjm.baihongyu.com/

你可能感兴趣的文章
Creating a Custom Page Layout in SharePoint 2013
查看>>
mysql foreignkey
查看>>
Django 中的自定义分页标签
查看>>
[转]ASP.NET自定义控件复杂属性声明持久性浅析
查看>>
PAT (Basic Level) Practise (中文)-卡拉兹(Callatz)猜想
查看>>
第八周进度总结
查看>>
axios 注意点
查看>>
刷新ListView刷新时的闪烁问题
查看>>
cuda c例程学习——eigenvalues(1)
查看>>
通过本地文件数据库查询手机归属地
查看>>
uva 10152 ShellSort
查看>>
前端之放大镜
查看>>
民航飞机专业词汇
查看>>
数据类型和变量
查看>>
通过excel快速拼接SQL
查看>>
json数据类型
查看>>
vue-cli的安装使用
查看>>
js实现页面重定向
查看>>
js数组
查看>>
点滴积累【other】---HTTP 错误 404.13 - Not Found,请求筛选模块被配置为拒绝超过请求内容长度的请求(转载)...
查看>>