1. 程式人生 > >linux上輕松安裝nginx

linux上輕松安裝nginx

-i debuginfo 版本 沒有 com rep location swd eas

小夥伴是不是也會感覺頭疼,尤其是通過安裝包進行安裝nginx的時候,簡直想摔電腦的節奏都有了。其實小編也有同樣的經歷,今天我們就來說一種簡單的安裝方式,那就是通過yum安裝nginx,那是相當簡單,下面我們就來說說安裝步驟吧。

1.首先在/etc/yum.repos.d 這個文件下面添加一個文件epel.repo,文件內容如下:

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

2.然後yum安裝nginx:

yum -y install nginx

如果出現如下錯誤

技術分享圖片

查找原因之後解決方法如下:

修改文件“/etc/yum.repos.d/epel.repo”, 將第一個的baseurl的註釋取消, mirrorlist註釋掉。即可。

3.之後在運行yum -y install nginx,報如下錯誤

技術分享圖片

這個錯誤是因為yum源的問題,原有的epel.repo這個文件中沒有nginx,所以這裏需要給他添加進去一個。(因為epel是yum源)

4.輸入命令:wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 下載一個對應版本的

rpm -ivh epel-release-6-8.noarch.rpm

5.再次運行yum -y install nginx 之後若還會報錯,類似如下錯誤

技術分享圖片

需要修改vi epel.repo 這個文件

技術分享圖片

最後再次運行yum -y install nginx 安裝成功,默認安裝在/etc下面,有一個nginx

6.進入nginx裏面,/nginx/conf.d文件下面,編譯vi default.conf 配置文件在這個默認的文件下面

需要增加一段內容

#設定Nginx狀態訪問地址
location /status {
stub_status on;
access_log on;
auth_basic "NginxStatus";
#auth_basic_user_file conf/htpasswd;
} 這個用於監控nginx

7.保存退出之後,輸入:nginx -t 查看是否成功

最後一步:

啟動nginx:nginx

關閉nginx:nginx -s stop

linux上輕松安裝nginx