2019独角兽企业重金招聘Python工程师标准>>>

用yum安装软件发现报错 解决This system is not registered with RHN 1.使用命令 cd /etc/yum.repos.d/ 进入yum的配置目录。 2.在终端中输入 wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo 命令,下载CentOS- Base.repo文件。 3.然后将原有的rhel-debuginfo.repo备份一下,使用命令mv CentOS-Base.repo rhel-debuginfo.repo,将CentOS- Base.repo重命名成rhel-debuginfo.repo。 4.成功以后,使用yum install build-essential安装成功。

安装nginx

1、准备工作 选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL。 Nginx是C写的,需要用GCC编译;Nginx的Rewrite和HTTP模块会用到PCRE;Nginx中的Gzip用到zlib; 用命令“# gcc”,查看gcc是否安装;如果出现“gcc: no input files”信息,说明已经安装好了。 否则,就需要用命令“# yum install gcc”,进行安装了!一路可能需要多次输入y,进行确认。 安装好后,可以再用命令“#gcc”测试,或者用命令“# gcc -v”查看其版本号。 同样方法,用如下命令安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思):

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

2、下载并安装 创建目录(nginx-src)并进去;然后,从官方地址(http://nginx.org/)下载,解压,配置,编译,安装:

# mkdir nginx-src && cd nginx-src
# wget http://nginx.org/download/nginx-1.10.3.tar.gz
# tar xzf nginx-1.10.3.tar.gz
# cd nginx-1.10.3
# ./configure
# make
# make install
# whereis nginx
nginx: /usr/local/nginx

默认的安装路径为:/usr/local/nginx;跳转到其目录下sbin路径下,便可以启动或停止它了。

[root@localhost sbin]# ./nginx -h
nginx version: nginx/1.10.3
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]Options:-?,-h         : this help-v            : show version and exit-V            : show version and configure options then exit-t            : test configuration and exit-T            : test configuration, dump it and exit-q            : suppress non-error messages during configuration testing-s signal     : send signal to a master process: stop, quit, reopen, reload-p prefix     : set prefix path (default: /usr/local/nginx/)-c filename   : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration file

启动:./nginx 停止:./nginx -s stop

3、添加到系统服务 使用命令“# vi /etc/init.d/nginx”,打开编辑器,输入如下内容:

#!/bin/sh
# chkconfig: 2345 85 15
# Startup script for the nginx Web Server
# description: nginx is a World Wide Web server.
# It is used to serve HTML files and CGI.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx deamon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME  test -x $DAEMON || exit 0  d_start(){  $DAEMON || echo -n "already running"
}  d_stop(){  $DAEMON -s quit || echo -n "not running"
}  d_reload(){  $DAEMON -s reload || echo -n "can not reload"
}  case "$1" in
start)  echo -n "Starting $DESC: $NAME"  d_start  echo "."
;;
stop)  echo -n "Stopping $DESC: $NAME"  d_stop  echo "."
;;
reload)  echo -n "Reloading $DESC conf..."  d_reload  echo "reload ."
;;
restart)  echo -n "Restarting $DESC: $NAME"  d_stop  sleep 2  d_start  echo "."
;;
*)  echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2  exit 3
;;
esac  exit 0

保存退出后,再使用下面的命令,使其可执行;然后,添加配置并查看。 可用chkconfig修改其值,也可用ntsysv工具改变是否自启动。

# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on/off
# chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

nginx配置

upstream boss {server 127.0.0.1:8080;}server {listen       80;server_name  boss.example.com;#charset koi8-r;#access_log  logs/host.access.log  main;location /admin {proxy_pass http://boss/admin;#下面两条如果不加的话,会导致静态文件解析出异常proxy_set_header Host $host;proxy_set_header X-Forward-For $remote_addr;   }
  upstream backend {#ip_hash;server 192.168.1.251;server 192.168.1.252;server 192.168.1.247;}server {listen       80;server_name  2;location / {#设置主机头和客户端真实地址,以便服务器获取客户端真实IPproxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#禁用缓存proxy_buffering off;#反向代理的地址proxy_pass http://backend;     }}

转载于:https://my.oschina.net/miaojiangmin/blog/831164

centos中安装nginx相关推荐

  1. CentOS 中安装nginx

    Centos6.8 yum  安装 nginx  1:使用yum安装nginx,安装nginx库 [root@hadoop110 //]# rpm -Uvh http://nginx.org/pack ...

  2. linux slf4j.rpm,Centos下安装nginx rpm包

    1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/centos/6 ...

  3. linux nginx rpm 安装配置,Centos下安装nginx rpm包

    1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/centos/6 ...

  4. CentOS rpm安装Nginx和配置

    CentOS rpm安装Nginx和配置 官方下载地址: http://nginx.org/en/download.html 介绍 Nginx("engine x")是一款由俄罗斯 ...

  5. 如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)

    本文介绍如何在FreeBSD 13系统中安装Nginx.MySQL.和PHP服务. 系统环境 FreeBSD 13.0-RELEASE 更新系统 在安装任何软件之前更新系统是一个好习惯,以便检查系统更 ...

  6. 在Ubuntu/Fedora/CentOS中安装Gitblit

    在Ubuntu/Fedora/CentOS中安装Gitblit Git是一款注重速度.数据完整性.分布式支持和非线性工作流的分布式版本控制工具.Git最初由Linus Torvalds在2005年为L ...

  7. 安装32位mysql报错_在CentOS中安装32位或64位MySql报错error: Failed dependencies解决办法...

    在CentOS中安装MySql报错error: Failed dependencies解决办法 安装64位MySql报错内容如下: error: Failed dependencies: libaio ...

  8. CentOS中安装git

    在CentOS中安装git步骤如下: (1)$ yum install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel g ...

  9. centos 多个mysql,Centos中安装多个MySQL数据的配置实例

    这篇文章主要为大家详细介绍了Centos中安装多个MySQL数据的配置实例,具有一定的参考价值,可以用来参考一下. 感兴趣的小伙伴,下面一起跟随512笔记的小编小韵来看看吧! 注:本文档做了两个MYS ...

最新文章

  1. php定时刷新token,PHP 定时任务获取微信access_token的简单示例
  2. 在Windows Mobile和Wince(Windows Embedded CE)下如何使用.NET Compact Framework开发进程管理程序...
  3. codevs 1576 最长严格上升子序列
  4. 关于重装系统后或打补丁后不能上网的问题的解决
  5. vins-mono中在rviz可视化下如何在world坐标系中让视角跟着相机移动
  6. nginx.conf文件详解
  7. 不懂函数能学c语言吗,不会函数能学C语言吗
  8. 柳传志:如何看人和用人
  9. VMware虚拟终端的下载及安装
  10. linux怎么用jconsole_怎么在linux jconsole
  11. Windows和Linux下搭建J2sdk的环境
  12. html4角星,运用ai绘画出5角星4角星三角形形状的设置步骤
  13. pip install 使用豆瓣源
  14. 微服务之springCloud-docker-comsumer(三)
  15. 计算机win7不断重启,win7系统电脑一开机就自动重启的解决方法
  16. 正式服务器有信号枪吗,吃鸡信号枪正式实装!我朝天开一枪引来了十个挂
  17. 关于高压线路如何防山火
  18. 【读书笔记】《读懂一本书》——如何读书不枯燥,读得懂,记得住
  19. 分布式消息队列基础知识
  20. 物理层一致性(Compliance)测试

热门文章

  1. vue cli 对解析的html内容的图片添加样式
  2. PHP三维数组变一维
  3. 如何初始化一个vue项目
  4. 上传文件的加密和下载文件解密
  5. 清结算内部勾兑业务一个比较有意思的问题整理
  6. Dubbo源码分析笔记-一(工程目录介绍)
  7. 虚拟化与Docker
  8. matplotlib中文乱码问题_MacOS解决Matplotlib的中文乱码问题
  9. Django 入门篇一
  10. RocketMQ如何解决分布式事务