1. 程式人生 > >centos7 安裝 nginx的兩種方法

centos7 安裝 nginx的兩種方法

centos7安裝nginx

第一種方式:通過yum安裝

直接通過 yum install nginx 肯定是不行的,因為yum沒有nginx,所以首先把 nginx 的源加入 yum 中。

執行下面的命令:

1.將nginx放到yum repro庫中
[[email protected] ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.檢視nginx資訊
[[email protected] ~]# yum info nginx
3.使用yum安裝ngnix [[email protected] ~]# yum install nginx 效果如下: [[email protected] ~]# yum install nginx 已載入外掛:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.usc.edu * extras: mirror.raystedman.net * updates: mirror.metrocast.net 正在解決依賴關係 --> 正在檢查事務 ---> 軟體包 nginx.x
86_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/ ---------------------------------------------------------------------- 驗證中 : 1
:nginx-1.10.1-1.el7.ngx.x86_64 1/1 已安裝: nginx.x86_64 1:1.10.1-1.el7.ngx 完畢! 4.啟動nginx [[email protected] ~]# service nginx start 5.檢視nginx版本 [[email protected] ~]# nginx -v 6.訪問nginx,現在你可以通過公網ip (本地可以通過 localhost /或 127.0.0.1 ) 檢視nginx 服務返回的資訊。 [[email protected] ~]# curl -i localhost 效果如下: ······ Welcome to nginx!。 ······ 7.nginx配置檔案位置在/etc/nginx/ [[email protected] /]# ll /etc/nginx/ 總用量 32 drwxr-xr-x. 2 root root 25 1012 13:11 conf.d -rw-r--r--. 1 root root 1007 531 22:09 fastcgi_params -rw-r--r--. 1 root root 2837 531 22:09 koi-utf -rw-r--r--. 1 root root 2223 531 22:09 koi-win -rw-r--r--. 1 root root 3957 531 22:09 mime.types lrwxrwxrwx. 1 root root 29 1012 13:11 modules -> ../../usr/lib64/nginx/modules -rw-r--r--. 1 root root 643 531 22:08 nginx.conf -rw-r--r--. 1 root root 636 531 22:09 scgi_params -rw-r--r--. 1 root root 664 531 22:09 uwsgi_params -rw-r--r--. 1 root root 3610 531 22:09 win-utf 8.實踐: 目的:修改服務名,接著從外部訪問這個服務 操作: a.修改nginx配置檔案 [[email protected] nginx]# vim /etc/nginx/conf.d/default.conf 修改server_name部分:server_name yytest.com; b.過載服務 [[email protected] nginx]# /usr/sbin/nginx -s reload c.從外部訪問nginx服務(192.168.10.11) 如在客戶機(192.168.10.10)的瀏覽器訪問:http://yytest.com d.你發現訪問不了,原因1,你沒有在hosts檔案做對映;原因2,及時你在hosts檔案中了對映,由於nginx伺服器的80埠堵塞或防火牆沒關 e.解決辦法: 步驟一:修改客戶機(192.168.10.10)的hosts檔案,使用SwitchHosts工具新增 192.168.10.11 yytest.com 步驟二:關閉防火牆,具體下文有說明 9.nginx常用操作 啟動: $ /usr/sbin/nginx或任意路徑下執行service nginx start(centos7是systemctl start nginx.service ) 重啟: $ /usr/sbin/nginx –s reload 停止: $ /usr/sbin/nginx –s stop 測試配置檔案是否正常: $ /usr/sbin/nginx –t

可能遇到的問題:

具體情況如下  1。本機能ping通虛擬機器  2。虛擬機器也能ping通本機  3。虛擬機器能訪問自己的web  4。本機無法訪問虛擬己的web  這個問題的原因是伺服器的80埠沒有開啟或防火牆沒有關閉

解決辦法

如果是centos6:
解決方法如下: 
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
然後儲存: 
/etc/rc.d/init.d/iptables save 
重啟防火牆 
/etc/init.d/iptables restart 

CentOS防火牆的關閉,關閉其服務即可: 
檢視CentOS防火牆資訊:/etc/init.d/iptables status 
關閉CentOS防火牆服務:/etc/init.d/iptables stop 
永久關閉防火牆: 
chkconfig –level 35 iptables off

如果是centos7
[[email protected] ~]# systemctl status firewalld.service

[[email protected] ~]# systemctl stop firewalld.service

[[email protected] ~]# systemctl disable firewalld.service

[[email protected] ~]# systemctl status firewalld.service

擴充套件知識:

啟動一個服務:systemctl start firewalld.service
關閉一個服務:systemctl stop firewalld.service
重啟一個服務:systemctl restart firewalld.service
顯示一個服務的狀態:systemctl status firewalld.service
在開機時啟用一個服務:systemctl enable firewalld.service
在開機時禁用一個服務:systemctl disable firewalld.service

檢視服務是否開機啟動:systemctl is-enabled firewalld.service;echo $?

檢視已啟動的服務列表:systemctl list-unit-files|grep enabled

第二種方式:通過手動下載安裝包解壓安裝

1.下載nginx包。
[root@localhost ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz

2.複製包到你的安裝目錄
[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.啟動nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx

5.檢視版本s
[root@localhost ~]# nginx -v

6.url訪問nginx localhost或127.0.0.1

相關推薦

詳解Centos7 下編譯安裝Nginx和yum搭建Nginx方法

Nginx 在併發與負載能力方面確實優於 apache,大多數網站都採用基於Nginx 來搭建網站。 下面就來介紹Nginx的搭建 一 原始碼安裝nginx 首先先來安裝Nginx,但是本地的yum倉庫中只有apache,並沒有Nginx,這就需要手動安裝了。 Nginx 的下載官網是這個http

centos7安裝mariadb10方法

一、用yum命令安裝 1、首先先要去mariadb網站獲取下載資訊,以便下一步編輯安裝的配置檔案: 瀏覽器開啟https://mariadb.org/blog/,找到你要裝的版本,點選標題如圖: 點選標題,到下一步,如圖: 點選mariadb apt and yum r

ubuntu下在終端下安裝與解除安裝軟體(方法)

安裝軟體 apt-get install softname1 softname2 softname3……解除安裝軟體 apt-get remove softname1 softname2 softname3……解除安裝並清除配置 apt-get remove --purge

centos7安裝nginx方法介紹

centos7安裝nginx 第一種方式:通過yum安裝 直接通過 yum install nginx 肯定是不行的,因為yum沒有nginx,所以首先把 nginx 的源加入 yum 中。 執行下面的命令: 1.將nginx放到yum repro庫中   複製程式

centos7安裝nginx方法

第一種方式:通過yum安裝 直接通過 yum install nginx 肯定是不行的,因為yum沒有nginx,所以首先把 nginx 的源加入 yum 中 執行下面的命令: 1.將nginx放到yum repro庫中 [[email protected] ~]# rpm -i

centos7 安裝 nginx方法

centos7安裝nginx 第一種方式:通過yum安裝 直接通過 yum install nginx 肯定是不行的,因為yum沒有nginx,所以首先把 nginx 的源加入 yum 中。 執行下面的命令: 1.將nginx放到yum repro庫中 [[email protecte

Centos6下安裝Nginx方法

一,通過yum命令安裝 1、作業系統版本的確認很重要,因為下一步我們要依靠這個來建立yum原始檔 2、建立 nginx.repo vi /etc/yum.repos.d/nginx.repo 檔案內容如下(如果是centos7,則對應的把數字6改成7): [ngi

Centos7網卡綁定的方法

bond 網卡綁定 一.傳統的bond方式(1)bond幾種主要模式介紹ü mode 0 load balancing (round-robin)模式 ,需要交換機端支持,支持多端口負載均衡,支持端口冗余,slave接口的mac相同ü mode 1active-backup模式,最大支持兩個端口,一

破解CentOS7 的root口令的方法

exit borde root 模式 entos family ini 光標移動 文件 1>.破解CentOS7 的root口令方法一 啟動時任意鍵暫停啟動 按e鍵進入編輯模式 將光標移動到linux16開始的行,添加內核參數

Centos 6編譯安裝httpd2.4的方法

下載 mpm include amp init apr-util con 腳本 spa 第一種方法 一、下載解壓 wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gzwget https://m

centos6.5 通過yum和源碼方法升級安裝內核

centos升級內核 yum安裝內核 源碼安裝內核 centos6.5 2.6.32yum方式安裝內核是安裝的最新版內核,不能選擇內核版本源碼方式安裝可以選擇內核版本進行安裝,源碼方式安裝較慢。 yum方式升級內核:cd /etc/yum.repos.d/下載導入公鑰wget --no-

Eclipse 安裝 SVN 插件的方法

最新 CA href get 使用 subclipse servlet 安裝目錄 ips eclipse裏安裝SVN插件,一般來說,有兩種方式: 直接下載SVN插件,將其解壓到eclipse的對應目錄裏 使用eclipse 裏Help菜單的“Install New S

安裝虛擬機器的方法(圖形化,指令碼)

圖形化安裝虛擬機器 安裝虛擬機器需要計算機CPU支援虛擬化功能 /proc/cpuinfo 中可以檢視CPU的具體資訊,指令集含有vmx(intel)或svm(amd)說明此CPU具有全虛擬化功能 虛擬機器圖形化安裝步驟 root使用者開啟virt-manager,可用f

logstash獲取nginx日誌 方法

獲取nginx日誌要寫grok 還有很多正則來做 那麼很多像我一樣的新手不知道該如何操作 下面我們來個簡單的 第一種 : 重點是: 把nginx的access.log日誌格式改成json型別 更重要的是下面兩行 log_format json '{"@timestamp"

Nginx簡單防禦CC攻擊的方法

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

Linux安裝(虛擬機器和雙系統方法

一、VMware虛擬機器 1.下載並安裝VMware: ①https://my.vmware.com/cn/web/vmware/free#desktop_end_user_computing/vmware_workstation_player/15_0 ②下載Ubuntu映象檔案:http

linux伺服器上安裝jdk的方法(yum+下載包)

這篇文章主要給大家介紹了關於在linux伺服器上安裝jdk的兩種方法,分別是利用yum安裝和從官網下載包安裝,文中通過示例程式碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧 前言 對於開發者來說,安裝jdk按理說是非常簡單的事,

linux上安裝解除安裝redis的方法

redis安裝參考文件 linux上安裝redis的兩種方法 一、 手動下載安裝 1 wget 獲取redis的資源 2 tar xzvf 。。。。.tar.gz 3 可以使用mv 指令把解壓的安裝包移動到想要安裝到的目錄下   cd redis-

[Linux] yum只下載不安裝rpm包的方法

方法一:通過yum自帶一個工具:yumdownloader [[email protected] ~]#  rpm -qa |grep yum-utils [[email protected] ~]# yum-y install yum-utils* [[email prote

CentOS7修改root密碼的方法(添加了CentOS6修改密碼的方法

咳咳,本來是篇很短的文章,被我越加越多,哈哈哈,下面是CentOS7的 1)啟動時任意鍵暫停啟動,按e鍵進入編輯模式,將游標移動到linux16開始的行的末尾,新增核心引數rd.break,按Ctrl-x啟動,進入緊急求援模式後輸入 mount -o remount,rw /sysroo