CentOS nginx 从 安装 到 自配yum本地源

CentOS nginx 从 安装 到 自配yum本地源

安装

第一步

首先确认没有安装过nginx
yum info nginx
若显示为available 则没有安装

第二步

进入yum的配置文件夹中
[root@zbq yum.repos.d]# cd /etc/yum.repos.d/

第三步

使用wget 安装ngnix到/etc/yum.repos.d/
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

第四步

接下来安装nginx
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
接下来会发现目录下多了一个 nginx.repo

[root@zbq yum.repos.d]# ll
total 36
-rw-r--r--. 1 root root 2523 Sep  6 09:23 ali-Base.repo
-rw-r--r--. 1 root root 1926 Sep  6 17:09 CentOS-Base.repo
-rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  576 Sep  6 17:07 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo
-rw-r--r--. 1 root root 4311 Oct 14  2011 nginx-release-centos-6-0.el6.ngx.noarch.rpm
-rw-r--r--. 1 root root  113 Sep  6 17:26 nginx.repo

第五步

再把ngnix.repo 作为源 使用 yum -l install nginx
安装完成之后ngnix就已经被安装完成了 版本为1.14
使用which nginx来查看

[root@zbq yum.repos.d]# which nginx
/usr/sbin/nginx

说明已经安装在标准目录下
现在查看nginx服务是否打开

[root@zbq yum.repos.d]# service nginx status
-b (pid  13451) is running...

若没有打开 使用 service nginx start 打开服务

现在使用浏览器输入自己的ip地址会出现nginx的欢迎界面 ,这个时候就代表nginx已经完全安装配置好了

若我现在让浏览器访问我的ip 的时候显示我自己的html文件

第一步

在/etc/nginx/ 路径下是nginx的文件,其中我们需要配置nginx.conf 文件来修改一些参数 路径为/etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf–>

user  root; #调整用户
worker_processes  8; #调整工作进程数量
error_log  /var/log/nginx/error.log warn; 
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;#连接池数量1024
}
http {
    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        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
   include /etc/nginx/conf.d/*.conf;#扩展配置的文件夹/etc/nginx/conf.d/

第二步

vi /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /usr/share/nginx/html; #存放html文件的地方
        index  index.html index.htm;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

第三步

cd /usr/share/nginx/html/

[root@zbq html]# ll
total 16
-rw-r--r--. 1 root root  537 Apr 17 23:47 50x.html
-rw-r--r--. 1 root root  612 Apr 17 23:47 index.html

现在在此路径下自己写一个html
vi my.html

this is my html

html内容怎么写都可以

自己制作一个yum源,并得到一个可访问的url,此url可以写到.repo文件当源路径

第一步

修改 local读取路径
vi /etc/nginx/nginx.conf

user  root;
worker_processes  8;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    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        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
   #include /etc/nginx/conf.d/*.conf;#注释掉扩展
#添加服务端和本地端 ,修改根路径  ,location为/data/www/web
server {
        listen 80;
        server_name www.lyd.com;
        location ~ / {
          index index.html;
          root /data/www/web;
        }
}
}

此时 /etc/nginx/conf.d/ 目录下的.conf 文件和默认 /etc/nginx/conf.d/default.conf 文件失效

第二步

创建相应的文件夹
mkdir -p /data/www/web/noarch

第三步

安装createrepo
1. yum -y createrepo
2. 复制nc 文件到 /data/www/web/noarch/RMPS
cp /etc/yum.repos.d/nginx-release-centos-6-0.el6.ngx.noarch.rpm /data/www/web/noarch/RPMS
使用createrepo制作repodata
createrepo -o ./ ./RPMS/
查看是否制作成功

[root@zbq noarch]# ll
total 68
-rwxr-xr-x. 1 root root 58132 Sep  6 19:06 nc-1.84-22.el6.x86_64.rpm
drwxr-xr-x. 2 root root  4096 Sep  6 18:48 repodata
drwxrwxrwx. 2 root root  4096 Sep  6 18:34 RPMS

发现已经成功制作了repodate文件
注意:createrepo 后必须跟一个文件,文件里面可以放多个rpm文件,将文件制作为repodata

第四步

在/etc/yum.repos.d/中制作制作自己的repo文件
vi /etc/yum.repos.d/qf.repo
在qf.repo中写入

#qf.repo
[qf]
name=qf repo
baseurl=http://192.168.8.200/noarch/
gpgcheck=0
enabled=1

到现在为止我们自己制作的yum源已经完成
但是为了让检查结果的时候比较明了,可以将其他repo文件写成.bak
cd /etc/yum.repos.d/
rename .repo .repo.bak ./*.repo
mv ./qf.repo.bak ./qf.repo

验证源文件

yum info nc
发现可以查询到 nc From repo : qf

[root@zbq yum.repos.d]# yum info nc
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name        : nc
Arch        : x86_64
Version     : 1.84
Release     : 22.el6
Size        : 109 k
Repo        : installed
From repo   : qf
Summary     : Reads and writes data across network connections using TCP or UDP
URL         : http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/
License     : BSD
Description : The nc package contains Netcat (the program is actually nc), a simple
            : utility for reading and writing data across network connections, using
            : the TCP or UDP protocols. Netcat is intended to be a reliable back-end
            : tool which can be used directly or easily driven by other programs and
            : scripts.  Netcat is also a feature-rich network debugging and
            : exploration tool, since it can create many different connections and
            : has many built-in capabilities.
            :
            : You may want to install the netcat package if you are administering a
            : network and you'd like to use its debugging and network exploration
            : capabilities.

假如显示没有安装 则可以测试安装
yum -y install nc
最后将repo文件名再修改回之前正确的名字
rename .repo.bak .repo ./*.repo.bak
修改后为正常repo文件

[root@zbq yum.repos.d]# ll
total 36
-rw-r--r--. 1 root root 2523 Sep  6 09:23 ali-Base.repo
-rw-r--r--. 1 root root 1926 Sep  6 17:09 CentOS-Base.repo
-rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  576 Sep  6 17:07 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo
-rw-r--r--. 1 root root 4311 Oct 14  2011 nginx-release-centos-6-0.el6.ngx.noarch.rpm
-rw-r--r--. 1 root root  113 Sep  6 17:26 nginx.repo
-rw-r--r--. 1 root root   86 Sep  6 18:52 qf.repo

end..

你可能感兴趣的:(yum制作,nginx安装,linux)