centos7安裝nginx的兩種方法介紹
centos7安裝nginx
第一種方式:通過(guò)yum安裝
直接通過(guò) yum install nginx 肯定是不行的,因?yàn)閥um沒(méi)有nginx,所以首先把 nginx 的源加入 yum 中。
運(yùn)行下面的命令:
1.將nginx放到y(tǒng)um repro庫(kù)中
[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.查看nginx信息
[root@localhost ~]# yum info nginx
3.使用yum安裝ngnix
[root@localhost ~]# yum install nginx
效果如下:
[root@localhost ~]# yum install nginx
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.usc.edu
* extras: mirror.raystedman.net
* updates: mirror.metrocast.net
正在解決依賴(lài)關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 nginx.x86_64.1.1.10.1-1.el7.ngx 將被 安裝
······
······
正在安裝 : 1:nginx-1.10.1-1.el7.ngx.x86_64
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/
----------------------------------------------------------------------
驗(yàn)證中 : 1:nginx-1.10.1-1.el7.ngx.x86_64 1/1
已安裝:
nginx.x86_64 1:1.10.1-1.el7.ngx
完畢!
4.啟動(dòng)nginx
[root@localhost ~]# service nginx start
5.查看nginx版本
[root@localhost ~]# nginx -v
6.訪問(wèn)nginx,現(xiàn)在你可以通過(guò)公網(wǎng)ip (本地可以通過(guò) localhost /或 127.0.0.1 ) 查看nginx 服務(wù)返回的信息。
[root@localhost ~]# curl -i localhost
效果如下:
······
Welcome to nginx!。
······
7.nginx配置文件位置在/etc/nginx/
[root@localhost /]# ll /etc/nginx/ 總用量 32 drwxr-xr-x. 2 root root 25 10月 12 13:11 conf.d -rw-r--r--. 1 root root 1007 5月 31 22:09 fastcgi_params -rw-r--r--. 1 root root 2837 5月 31 22:09 koi-utf -rw-r--r--. 1 root root 2223 5月 31 22:09 koi-win -rw-r--r--. 1 root root 3957 5月 31 22:09 mime.types lrwxrwxrwx. 1 root root 29 10月 12 13:11 modules -> ../../usr/lib64/nginx/modules -rw-r--r--. 1 root root 643 5月 31 22:08 nginx.conf -rw-r--r--. 1 root root 636 5月 31 22:09 scgi_params -rw-r--r--. 1 root root 664 5月 31 22:09 uwsgi_params -rw-r--r--. 1 root root 3610 5月 31 22:09 win-utf
8.實(shí)踐:
目的:修改服務(wù)名,接著從外部訪問(wèn)這個(gè)服務(wù)
操作:
a.修改nginx配置文件
[root@localhost nginx]# vim /etc/nginx/conf.d/default.conf
修改server_name部分:server_name yytest.com;
b.重載服務(wù)
[root@localhost nginx]# /usr/sbin/nginx -s reload
c.從外部訪問(wèn)nginx服務(wù)(192.168.10.11)
如在客戶(hù)機(jī)(192.168.10.10)的瀏覽器訪問(wèn):http://yytest.com
d.你發(fā)現(xiàn)訪問(wèn)不了,原因1,你沒(méi)有在hosts文件做映射;原因2,及時(shí)你在hosts文件中了映射,由于nginx服務(wù)器的80端口堵塞或防火墻沒(méi)關(guān)
e.解決辦法:
步驟一:修改客戶(hù)機(jī)(192.168.10.10)的hosts文件,使用SwitchHosts工具添加 192.168.10.11 yytest.com
步驟二:關(guān)閉防火墻,具體下文有說(shuō)明
9.nginx常用操作
啟動(dòng):
$ /usr/sbin/nginx或任意路徑下運(yùn)行service nginx start(centos7是systemctl start nginx.service )
重啟:
$ /usr/sbin/nginx –s reload
停止:
$ /usr/sbin/nginx –s stop
測(cè)試配置文件是否正常:
$ /usr/sbin/nginx –t
可能遇到的問(wèn)題:
具體情況如下 1。本機(jī)能ping通虛擬機(jī) 2。虛擬機(jī)也能ping通本機(jī) 3。虛擬機(jī)能訪問(wèn)自己的web 4。本機(jī)無(wú)法訪問(wèn)虛擬己的web 這個(gè)問(wèn)題的原因是服務(wù)器的80端口沒(méi)有打開(kāi)或防火墻沒(méi)有關(guān)閉
解決辦法
如果是centos6:
解決方法如下:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
然后保存:
/etc/rc.d/init.d/iptables save
重啟防火墻
/etc/init.d/iptables restart
CentOS防火墻的關(guān)閉,關(guān)閉其服務(wù)即可:
查看CentOS防火墻信息:/etc/init.d/iptables status
關(guān)閉CentOS防火墻服務(wù):/etc/init.d/iptables stop
永久關(guān)閉防火墻: chkconfig –level 35 iptables off
如果是centos7
[root@rhel7 ~]# systemctl status firewalld.service [root@rhel7 ~]# systemctl stop firewalld.service [root@rhel7 ~]# systemctl disable firewalld.service [root@rhel7 ~]# systemctl status firewalld.service
擴(kuò)展知識(shí):
啟動(dòng)一個(gè)服務(wù):systemctl start firewalld.service
關(guān)閉一個(gè)服務(wù):systemctl stop firewalld.service
重啟一個(gè)服務(wù):systemctl restart firewalld.service
顯示一個(gè)服務(wù)的狀態(tài):systemctl status firewalld.service
在開(kāi)機(jī)時(shí)啟用一個(gè)服務(wù):systemctl enable firewalld.service
在開(kāi)機(jī)時(shí)禁用一個(gè)服務(wù):systemctl disable firewalld.service
查看服務(wù)是否開(kāi)機(jī)啟動(dòng):systemctl is-enabled firewalld.service;echo $?
查看已啟動(dòng)的服務(wù)列表:systemctl list-unit-files|grep enabled
第二種方式:通過(guò)手動(dòng)下載安裝包解壓安裝
1.下載nginx包。
[root@localhost ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz
2.復(fù)制包到你的安裝目錄
[root@localhost ~]# cp nginx-1.10.1.tar.gz /usr/local/
3.解壓
[root@localhost ~]# tar -zxvf nginx-1.10.1.tar.gz [root@localhost ~]# cd nginx-1.10.1
4.啟動(dòng)nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
5.查看版本s
[root@localhost ~]# nginx -v
6.url訪問(wèn)nginx localhost或127.0.0.1
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Linux內(nèi)核設(shè)備驅(qū)動(dòng)之proc文件系統(tǒng)筆記整理
今天小編就為大家分享一篇關(guān)于Linux內(nèi)核設(shè)備驅(qū)動(dòng)之proc文件系統(tǒng)筆記整理,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12
Linux服務(wù)使用寶塔面板搭建網(wǎng)站并發(fā)布公網(wǎng)訪問(wèn)
寶塔面板作為簡(jiǎn)單好用的服務(wù)器運(yùn)維管理面板,它支持Linux/Windows系統(tǒng),本文我們將演示使用寶塔面板快速簡(jiǎn)單搭建本地web網(wǎng)站,并做內(nèi)網(wǎng)穿透,實(shí)現(xiàn)不在同個(gè)局域網(wǎng)下的用戶(hù)也可以訪問(wèn)到本地web站點(diǎn),無(wú)需公網(wǎng)IP,也不用設(shè)置路由器,需要的朋友可以參考下2023-08-08
springcloud alibaba nacos linux配置的詳細(xì)教程
這篇文章主要介紹了springcloud alibaba nacos linux配置,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Linux中文件描述符fd與文件指針FILE*互相轉(zhuǎn)換實(shí)例解析
這篇文章主要介紹了Linux中文件描述符fd與文件指針FILE*互相轉(zhuǎn)換實(shí)例解析,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01
Linux下activeMQ的啟動(dòng)和停止命令方式
文章介紹了在Linux環(huán)境下啟動(dòng)和停止Apache ActiveMQ的步驟,啟動(dòng)前需要確保服務(wù)未運(yùn)行,使用`./activemq start`命令啟動(dòng),停止時(shí)使用`./activemq stop`命令,啟動(dòng)后可以通過(guò)訪問(wèn)`http://127.0.0.1:8161/admin/`來(lái)驗(yàn)證服務(wù)是否成功啟動(dòng)2024-12-12
linux kernel 打印函數(shù)指針對(duì)應(yīng)的函數(shù)名方法
下面小編就為大家?guī)?lái)一篇linux kernel 打印函數(shù)指針對(duì)應(yīng)的函數(shù)名方法。小編覺(jué)得挺不錯(cuò)的?,F(xiàn)在就分享給大家。也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
Linux內(nèi)核設(shè)備驅(qū)動(dòng)之Linux內(nèi)核基礎(chǔ)筆記整理
今天小編就為大家分享一篇關(guān)于Linux內(nèi)核設(shè)備驅(qū)動(dòng)之Linux內(nèi)核基礎(chǔ)筆記整理,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12
apache的AllowOverride以及Options使用詳解
通常利用Apache的rewrite模塊對(duì) URL 進(jìn)行重寫(xiě)的時(shí)候, rewrite規(guī)則會(huì)寫(xiě)在 .htaccess 文件里。但要使 apache 能夠正常的讀取.htaccess 文件的內(nèi)容,就必須對(duì).htaccess 所在目錄進(jìn)行配置2012-11-11

