centos 安裝nginx 和php

來源:互聯網
上載者:User

標籤:http   os   strong   檔案   io   art   cti   html   

1.官方:http://nginx.org/download/nginx-1.6.0.tar.gz

一:nginx

0.

yum install gcc gcc-c++

yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel

yum -y install perl-devel perl-ExtUtils-Embed

yum -y install gcc automake autoconf libtool make

yum install pcre 

//pcreRegex的庫

1. wget http://nginx.org/download/nginx-1.6.0.tar.gz

2. tar zxvf nginx-1.6.0.tar.gz

3. cd nginx-1.6.0

4. ./configure –help 查看協助檔案  --prefix=PATH

4. ./configure

5.make && make install

已經預設安裝/usr/local/nginx下,設定檔在…conf下,.default 是備份的

6.啟動  /usr/local/nginx/sbin/nginx

7.開啟防火牆的80連接埠

vi /etc/sysconfig/iptables

1.修改vi /etc/sysconfig/iptables命令添加使防火牆開放80連接埠

  1. -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 
  2.  

2.關閉/開啟/重啟防火牆

  1. /etc/init.d/iptables stop 
  2.  
  3. #start 開啟 
  4.  
  5. #restart 重啟 
  6.  

3.永久性關閉防火牆

  1. chkconfig --level 35 iptables off 
  2.  
  3. /etc/init.d/iptables stop 
  4.  
  5. iptables -P INPUT DROP

 

8.測試,瀏覽器開啟ip,看nginx第一頁

二:php

0.

yum -y install gcc automake autoconf libtool makeyum -y install gcc gcc-c++ glibcyum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
 

1.下載wget http://cn2.php.net/get/php-5.3.28.tar.gz/from/this/mirror

2. tar zxvf mirror

3.cd php5.3.28

3../configure –help     prefix      apache的模組  apxs     enable –fpm

3. ./configure --prefix=/usr/local/php --enable-fpm

4.make && make install

5.php設定檔產生

cp php-fpm.conf.default  php-fpm.conf

6.運行php  ./sbin/php-fpm

7.查看進程

ps aux|grep php

 

三:整合php和nginx

php連接埠:9000

1.vi /usr/local/nginx/conf/nginx.conf

set nu

2.65行,去掉注釋

3.69行:/scripts  改為 $document_root

4.測試一下設定檔

/usr/local/nginx/sbin/nginx –t

5.重啟

/usr/local/nginx/sbin/nginx –s reload

 

四:nginx訊號控制

QUTI 優雅的關閉

HUP 修改設定檔,平滑重啟

kill –HUB 4873  //進程號  ps aux|grep nginx

 

Nginx的訊號控制

TERM, INT

Quick shutdown

QUIT

Graceful shutdown 優雅的關閉進程,即等請求結束後再關閉

HUP

Configuration reloadStart the new worker processes with

a new configurationGracefully shutdown the old worker processes

改變更配置置檔案,平滑的重讀設定檔

USR1

Reopen the log files 重讀日誌,在日誌按月/日分割時有用

USR2

Upgrade Executable on the fly 平滑的升級

WINCH

Gracefully shutdown the worker processes 優雅關閉舊的進程(配合USR2來進行升級)

具體文法:

Kill -訊號選項 nginx的主進程號

Kill -HUP 4873

Kill -訊號控制 `cat /xxx/path/log/nginx.pid`

 

五:虛擬機器主機

Nginx配置段

Event {

// 一般是配置nginx進程與串連的特性

// 如幾個同時工作

worker_connections 1024; // 這是指 一個子進程最大允許連1024個串連

}

http { //這是配置http伺服器的主要段

Server1 { // 這是虛擬機器主機段

Location { //定位,把特殊的路徑或檔案再次定位 ,如image目錄單獨處理

} /// 如.php單獨處理

}

Server2 {

}

}

例子1: 基於網域名稱的虛擬機器主機

server {

listen 80; #監聽連接埠

server_name a.com; #監聽網域名稱

location / {

root /var/www/a.com; #根目錄定位

index index.html;

}

}

例子2: 基於連接埠的虛擬機器主機配置

server {

listen 8080;

server_name 192.168.1.204;

location / {

root /var/www/html8080;

index index.html;

}

}

2.殺掉進程 pkill –9 nginx    pkill-9 php-fpm   rm –rf nginx  rm –rf php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.