centos中安装nginx
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相关推荐
- CentOS 中安装nginx
Centos6.8 yum 安装 nginx 1:使用yum安装nginx,安装nginx库 [root@hadoop110 //]# rpm -Uvh http://nginx.org/pack ...
- linux slf4j.rpm,Centos下安装nginx rpm包
1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/centos/6 ...
- linux nginx rpm 安装配置,Centos下安装nginx rpm包
1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/centos/6 ...
- CentOS rpm安装Nginx和配置
CentOS rpm安装Nginx和配置 官方下载地址: http://nginx.org/en/download.html 介绍 Nginx("engine x")是一款由俄罗斯 ...
- 如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)
本文介绍如何在FreeBSD 13系统中安装Nginx.MySQL.和PHP服务. 系统环境 FreeBSD 13.0-RELEASE 更新系统 在安装任何软件之前更新系统是一个好习惯,以便检查系统更 ...
- 在Ubuntu/Fedora/CentOS中安装Gitblit
在Ubuntu/Fedora/CentOS中安装Gitblit Git是一款注重速度.数据完整性.分布式支持和非线性工作流的分布式版本控制工具.Git最初由Linus Torvalds在2005年为L ...
- 安装32位mysql报错_在CentOS中安装32位或64位MySql报错error: Failed dependencies解决办法...
在CentOS中安装MySql报错error: Failed dependencies解决办法 安装64位MySql报错内容如下: error: Failed dependencies: libaio ...
- CentOS中安装git
在CentOS中安装git步骤如下: (1)$ yum install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel g ...
- centos 多个mysql,Centos中安装多个MySQL数据的配置实例
这篇文章主要为大家详细介绍了Centos中安装多个MySQL数据的配置实例,具有一定的参考价值,可以用来参考一下. 感兴趣的小伙伴,下面一起跟随512笔记的小编小韵来看看吧! 注:本文档做了两个MYS ...
最新文章
- php定时刷新token,PHP 定时任务获取微信access_token的简单示例
- 在Windows Mobile和Wince(Windows Embedded CE)下如何使用.NET Compact Framework开发进程管理程序...
- codevs 1576 最长严格上升子序列
- 关于重装系统后或打补丁后不能上网的问题的解决
- vins-mono中在rviz可视化下如何在world坐标系中让视角跟着相机移动
- nginx.conf文件详解
- 不懂函数能学c语言吗,不会函数能学C语言吗
- 柳传志:如何看人和用人
- VMware虚拟终端的下载及安装
- linux怎么用jconsole_怎么在linux jconsole
- Windows和Linux下搭建J2sdk的环境
- html4角星,运用ai绘画出5角星4角星三角形形状的设置步骤
- pip install 使用豆瓣源
- 微服务之springCloud-docker-comsumer(三)
- 计算机win7不断重启,win7系统电脑一开机就自动重启的解决方法
- 正式服务器有信号枪吗,吃鸡信号枪正式实装!我朝天开一枪引来了十个挂
- 关于高压线路如何防山火
- 【读书笔记】《读懂一本书》——如何读书不枯燥,读得懂,记得住
- 分布式消息队列基础知识
- 物理层一致性(Compliance)测试