CentOS7.2安裝Nginx過程筆記,由于學(xué)習(xí)的需要,這段時間學(xué)一點(diǎn)“nginx”。今天學(xué)習(xí)一下Nginx安裝,留個筆記
創(chuàng)新互聯(lián)主營達(dá)日網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,達(dá)日h5微信平臺小程序開發(fā)搭建,達(dá)日網(wǎng)站營銷推廣歡迎達(dá)日等地區(qū)企業(yè)咨詢
查看CentOS的版本
使用一下命令來查看一下當(dāng)前系統(tǒng)的版本
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
添加資源庫
在 CentOS 系統(tǒng)上安裝 Nginx ,你得先去添加一個資源庫,像這樣:
vim /etc/yum.repos.d/nginx.repo
使用 vim 命令去打開 /etc/yum.repos.d/nginx.repo ,如果 nginx.repo 不存在,就會去創(chuàng)建一個這樣的文件,打開以后按一下小 i 鍵,進(jìn)入編輯模式,然后復(fù)制粘貼下面這幾行代碼,完成以后按 esc 鍵退出,再輸入:wq (保存并退出)
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
yum 命令去安裝 nginx
完成上邊操作以后,我們就可以使用 yum 命令去安裝 nginx 了
yum install nginx
安裝成功:
Loaded plugins: fastestmirror, langpacks nginx | 2.9 kB 00:00 nginx/7/x86_64/primary_db | 14 kB 00:01 Loading mirror speeds from cached hostfile * base: mirrors.sina.cn * extras: mirrors.btte.net * updates: mirrors.sina.cn Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 1:1.10.1-1.el7.ngx will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: nginx x86_64 1:1.10.1-1.el7.ngx nginx 640 k Transaction Summary ================================================================================ Install 1 Package Total download size: 640 k Installed size: 2.1 M Is this ok [y/d/N]: y Downloading packages: nginx-1.10.1-1.el7.ngx.x86_64.rpm | 640 kB 00:27 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:nginx-1.10.1-1.el7.ngx.x86_64 1/1 ---------------------------------------------------------------------- Thanks for using nginx! Please find the official documentation for nginx here: * http://nginx.org/en/docs/ Commercial subscriptions for nginx are available on: * http://nginx.com/products/ ---------------------------------------------------------------------- Verifying : 1:nginx-1.10.1-1.el7.ngx.x86_64 1/1 Installed: nginx.x86_64 1:1.10.1-1.el7.ngx Complete!
測試nginx配置文件
當(dāng)你執(zhí)行 nginx -t 得時候,nginx會去測試你得配置文件得語法,并告訴你配置文件是否寫得正確,同時也告訴了你配置文件得路徑:
nginx -t
打印如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
說明配置文件成功!
centos7.0+ nginx實現(xiàn)停止、啟動、重啟
在CentOS7中,進(jìn)行chkconfig命令操作時會發(fā)現(xiàn)有類似“systemctl.....”的提示,systemctl可以簡單實現(xiàn)service和chkconfig的結(jié)合,這樣通過一個命令就可以實現(xiàn)兩個命令的功能。
systemctl命令的基本操作格式是:
systemctl [OPTIONS...] {COMMAND}...
以nginx服務(wù)為例,實現(xiàn)停止、啟動、重啟的動作如下:
systemctl stop nginx.service systemctl start nginx.service systemctl restart nginx.service
檢查服務(wù)狀態(tài)
systemctl status nginx.service
使服務(wù)開機(jī)啟動
systemctl enable nginx.service
取消服務(wù)開機(jī)啟動
systemctl disable nginx.service
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。