1.虚拟机可以连接网络(提前设置好 具体百度)
2.没有下载Apache的httpd服务 如果以前有 现在下载的Nginx会与其端口冲突 都用的80端口
(如果有的话 需要修改httpd端口 避免冲突 或者卸载吧 具体百度)
3.我这是新配的虚拟机 什么都没有 刚配配置好网络
4.我使用的镜像是CentOS6.5
然后我参考的博客 CentOS6.5 下Nginx 的安装与配置 5…安装必须环境
nginx的编译需要c++,同时prce(重定向支持)和openssl(https支持)也需要安装。

请顺序安装依赖

1  yum install gcc-c++  
2  yum -y install pcre*  
3  yum -y install openssl*

2.,下载nginx-1.9.9.tar.gz,可放在 /usr/local/ 目录下 ps:我这里使用的老本你可以尝试新版

1  [root@testsix ~]# cd /usr/local/  
2  [root@testsix local]# wget http://nginx.org/download/nginx-1.9.9.tar.gz

3.解压及编译

1 [root@testsix local]# tar -zxvf nginx-1.9.9.tar.gz

4.进入nginx目录

1 [root@testsix local]# cd nginx-1.9.9

5.设置安装目录为 /usr/local/nginx**

1 [root@testsix nginx-1.9.9]# ./configure --prefix=/usr/local/nginx

开始编译安装

1  [root@testsix nginx-1.9.9]# make  
2  [root@testsix nginx-1.9.9]# make install

基本上就这样 执行过程就不贴出来了
我是没有出现错误 因为这台机子很干净 刚配置的 如果有错误 请百度解决下哈

然后吧 就在 /usr/local/下有 /nginx 这个目录了
启动nginx服务

进入安装目录 /usr/local/nginx

1 [root@testsix ~]# cd /usr/local/nginx/sbin/  
2 [root@testsix sbin]# ./nginx

查看进程,可以看到nginx的master和worker进程

[root@testsix sbin]# ps -ef | grep nginx 
root       1986   1711  0 17:11 pts/0    00:00:00 vim ./nginx.conf
root       4336   4315  0 17:19 pts/3    00:00:00 vim /usr/local/nginx/conf/
root       4362      1  0 17:27 ?        00:00:00 nginx: master process ./nginx
root       4363   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4364   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4365   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4366   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4367   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4368   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4369   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4370   4362  0 17:27 ?        00:00:00 nginx: worker process
root       4875   1711  0 19:42 pts/0    00:00:00 ./nginx
root       4877   1711  0 19:42 pts/0    00:00:00 grep nginx
[root@testsix sbin]#

可以通过访问ip:80测试,看到页面这样的提示就说明安装成功

如果访问不了 可能是你防火墙没关
可以使用 service iptables status 查看防火墙状态

要关闭防火墙
一般没什么特殊情况 我们习惯设置永久关闭防火墙 即使用 chkconfig iptables off
关闭后可以使用 service iptables status 查看防火墙状态

一.Linux下开启/关闭防火墙命令
1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop

nginx 根据源地址禁用 nginx配置yum源_CentOS

我参考的这篇博客还有下面的 各位可以转过去看下

这个脚本 就是配置Nginx服务的开启和关闭的 然后再配合chkconfig命令设置永久开启和永久关闭

nginx 根据源地址禁用 nginx配置yum源_Nginx_02

这样Nginx服务就启动好了(如果想下次不用手动开启服务 就生效可以通过地址访问到80端口 那就必须设置永久开启 方法可百度)

ok

然后

设置Nginx的配置文件

我们源码编译的这种生成的目录跟使用yum源安装Nginx的好像是不太一样的!
现在我的目录是这样的

[root@testsix nginx]# cd /usr/local/nginx
[root@testsix nginx]# ll
total 36
drwx------. 2 root root 4096 Aug 27 17:27 client_body_temp
drwxr-xr-x. 2 root root 4096 Aug 27 17:58 conf
drwx------. 2 root root 4096 Aug 27 17:27 fastcgi_temp
drwxr-xr-x. 2 root root 4096 Aug 27 17:19 html
drwxr-xr-x. 2 root root 4096 Aug 27 17:27 logs
drwx------. 2 root root 4096 Aug 27 17:27 proxy_temp
drwxr-xr-x. 2 root root 4096 Aug 27 17:19 sbin
drwx------. 2 root root 4096 Aug 27 17:27 scgi_temp
drwx------. 2 root root 4096 Aug 27 17:27 uwsgi_temp
[root@testsix nginx]#

我们要配置的就是conf下的nginx.conf

同时注意这几个文件的位置

mime.types

access.log

error.log

nginx.pid 这个好像没有 是我创建的

nginx 根据源地址禁用 nginx配置yum源_Yum_03


nginx 根据源地址禁用 nginx配置yum源_CentOS_04

然后进入[root@testsix conf]# vi nginx.conf 有些东西不知道是不是必须配置
反正我配置了 也成功了
先将一些注释的地方放开 对照下面文件
看我文件

1.将user 改为root
2.worker_processes 设为 8
3.error_log /usr/local/nginx/logs/error.log 改为全路径
4.pid /usr/local/nginx/logs/nginx.pid 全路径 好像没有这个文件 我手动创建的 不知道是不是它自己创建
5.全路径 include /usr/local/nginx/conf/mime.types
6.log_format main 三句话 放开注释
7.access_log /usr/local/nginx/logs/access.log main 全路径
8.server_name www.testsix.com 设置为自己的映射的地址 这个目录是我们自己配的 使用mkdir -p /data/www/web 递归创建 如果没有的话
10. autoindex on;加一句这个

这是我的映射地址

[root@testsix ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.37.126 testsix www.testsix.com
[root@testsix ~]#
192.168.37.126 testsix www.testsix.com 就是加了这一句话

对了 说到这里
我这新配的机子 除了设置联网
还改了主机名(永久修改)、
还有hosts映射文件
1)查看主机名基本语法:

[root@testsix ~]# hostname
testsix

临时修改
[root@testsix ~]# hostname testsix
永久修改hostname (注意主机名不要有下滑线)

[root@testsix ~]# vi /etc/sysconfig/network



NETWORKING=yes
HOSTNAME=testsix

保存退出

2)配置域名解析器

打开/etc/hosts
[root@hadoop101 /]# vim /etc/hosts
添加如下内容
192.168.25.101 hadoop101

进入:vi /etc/sysconfig/network 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.37.126 testsix www.testsix.com

配置文件

user  root;
worker_processes  8;

error_log  /usr/local/nginx/logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /usr/local/nginx/logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include      /usr/local/nginx/conf/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  /usr/local/nginx/logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
 server {
        listen       80;
        server_name  www.testsix.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /data/www/web;
            index  index.html index.htm;
            autoindex on;
        }
}

ok 配置文件配置完成
创建nginx的root根目录
根目录/data/www/web 我们也创建了

将准备好用来测试的rpm包上传到服务器
这里使用的是nc-1.84-22.el6.x86_64.rpm 包
这是一个没有其他依赖的包 所以只要它一个就行

我使用的fiezilla这个软件上传的文件 可以百度具体使用

生成repodata目录(需要先按照createrepo: yum -y install createrepo)

这个createrepo需要先安装

yum -y install createrepo

然后使用命令 注意这个

noarch目录需要手动 创建

上传的nc的rpm包也需要传到这个目录下

然后才能使用这个命令

createrepo -o /www/data/web/noarch/ /www/data/web/noarch/

6、验证是否能使用自己的yum源

在/etc/yum.repos.d/ 创建自己的 名.repo文件
内容如下:

# nginx.repo

[nc]
name=nc repo
baseurl=http://hadoop01/noarch/     ##路径为到repodata这一层即可
gpgcheck=0
enabled=1

具体步骤
rename .repo .repo.bak *
vi nginx.repo
填入内容即可

[root@testsix yum.repos.d]# ll
total 16
-rw-r--r--. 1 root root 1926 Nov 27  2013 CentOS-Base.repo
-rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  630 Nov 27  2013 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo
[root@testsix yum.repos.d]# mv *.repo *.repo.bak
mv: target `*.repo.bak' is not a directory
[root@testsix yum.repos.d]# rename .repo .repo.bak *
[root@testsix yum.repos.d]# ll
total 16
-rw-r--r--. 1 root root 1926 Nov 27  2013 CentOS-Base.repo.bak
-rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo.bak
-rw-r--r--. 1 root root  630 Nov 27  2013 CentOS-Media.repo.bak
-rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo.bak
[root@testsix yum.repos.d]# vi nginx.repo

7、使用命令测试

下载测试前 需要清空缓存并重新构建
yum clean all
yum makecache
然后再执行下面的命令
yum repolist
yum info nc
yum install -y nc 成功安装就okay

[root@testsix yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                                                    repo name                                                                       
nc                                                                                         ncrepo                                                                          
repolist: 1

有东西不是0就是对的
我第一次时0
没有东西
因为我的nc的rpm包放错位置了

然后 yum info nc 会出来跟多信息

[root@testsix yum.repos.d]# yum info nc
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
Name        : nc
Arch        : x86_64
Version     : 1.84
Release     : 22.el6
Size        : 57 k
Repo        : nc
。。。。。。等

然后测试安装 Complete! 出现complete代表成功

[root@testsix yum.repos.d]# yum install -y nc
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nc.x86_64 0:1.84-22.el6 will be installed
--> Finished Dependency Resolution

、、、、、、
、。、、、、
、。、、、

Installed:
  nc.x86_64 0:1.84-22.el6                                                                                                                                                 

Complete!

这样代表本地Yum源配置成功了!!!