国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

lnmp環(huán)境配置之安裝配置Nginx與PHP教程

2024-08-27 23:59:05
字體:
來源:轉載
供稿:網(wǎng)友

lnmp環(huán)境中nginx與php是一個重頭戲了,很多朋友在配置這一步時都要折騰很多,在此小編也同樣是折騰了,下面我整理了一篇lnmp環(huán)境中安裝配置Nginx與PHP教程,希望例子可以幫助到大家.

安裝Nginx的方式有很多種,這里我們還是編譯源碼進行安裝,使用下列命令:

  1. $ wget http://nginx.org/download/nginx-1.6.2.tar.gz 
  2. $ tar -zxvf nginx-1.6.2.tar.gz 
  3. $ cd nginx-1.6.2 
  4. $ ./configure --prefix=/usr/local/nginx 
  5. $ make 
  6. $ sudo make install 

如果安裝過程中出現(xiàn)如下錯誤:

  1. ./configure: error: the HTTP rewrite module requires the PCRE library. 
  2. You can either disable the module by using --without-http_rewrite_module 
  3. option, or install the PCRE library into the system, or build the PCRE library 
  4. statically from the source with nginx by using --with-pcre=<path> option. 

則需要先安裝pcre:

$ sudo yum install pcre-devel

安裝完成之后,我們的Nginx安裝目錄在/usr/local/nginx,接下來修改nginx的配置文件(/usr/local/nginx/conf/nginx.conf),使其能夠處理php腳本.

  1. worker_processes  1; 
  2. events { 
  3.   worker_connections  1024; 
  4. http { 
  5.   include       mime.types; 
  6.   default_type  application/octet-stream; 
  7.   sendfile        on; 
  8.   keepalive_timeout  65; 
  9.   server { 
  10.     listen       80; 
  11.     server_name  _; 
  12.     root /vagrant; 
  13.     location / { 
  14.       index  index.html index.htm index.php; 
  15.     } 
  16.     location /demo { 
  17.       index index.php; 
  18.       if (!-e $request_filename) { 
  19.           rewrite ^/demo/(.*)$ /demo/index.php?$1 last; 
  20.           break; 
  21.       } 
  22.     } 
  23.     error_page   500 502 503 504  /50x.html; 
  24.     location = /50x.html { 
  25.       root   html; 
  26.     } 
  27.     location ~ \.php$ { 
  28.       fastcgi_pass   127.0.0.1:9000; 
  29.       fastcgi_index  index.php; 
  30.       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
  31.       include        fastcgi_params; 
  32.     } 
  33.   } 

最后,啟動Nginx時,需要先啟動PHP-FPM.

  1. $ sudo /usr/local/php/sbin/php-fpm 
  2. $ sudo /usr/local/nginx/sbin/nginx 

對于Nginx的重啟以及關閉操作,可以使用以下命令.

$ sudo /usr/local/nginx/sbin/nginx -s [reload|restart|stop]

而PHP-FPM,則麻煩一點,需要先使用ps -ef|grep php-fpm獲取master process的進程ID,再使用kill -USR2:

  1. $ ps -ef|grep php-fpm 
  2. root      6221     1  0 02:17 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) 
  3. nobody    6222  6221  0 02:17 ?        00:00:00 php-fpm: pool www 
  4. nobody    6223  6221  0 02:17 ?        00:00:00 php-fpm: pool www 
  5. vagrant   6233  1623  0 02:18 pts/0    00:00:00 grep php-fpm 
  6. $ sudo kill -USR2 6221 

注意:-USR2參數(shù)為重啟,-INT參數(shù)為關閉.

創(chuàng)建虛擬主機:

  1. [root@os11728 httpd-2.2.22]# vi /usr/local/nginx/conf/vhosts/www_finet230_cn.conf 

內容如下:

  1. server { 
  2.       listen       8080; 
  3.       server_name  ng.fine230.cn finet85.cn; 
  4.  
  5.        root  /var/www/root/ng_finet230_cn; 
  6.  
  7.   #激活/關閉自動索引 
  8.      autoindex on; 
  9.  
  10.       #設定索引時文件大小的單位(B,KB, MB 或 GB) 
  11.      #默認為on,顯示出文件的確切大小,單位是bytes。 
  12.      #改為off后,顯示出文件的大概大小,單位是kB或者MB或者GB 
  13.      autoindex_exact_size off; 
  14.  
  15.       #開啟以本地時間來顯示文件時間的功能。默認為關(GMT時間) 
  16.      #默認為off,顯示的文件時間為GMT時間。 
  17.      #改為on后,顯示的文件時間為文件的服務器時間 
  18.      autoindex_localtime on; 
  19.  
  20.       #charset koi8-r; 
  21.  
  22.       location / { 
  23.           index  index.html index.htm index.php; 
  24.       } 
  25.  
  26.       #error_page  404              /404.html; 
  27.  
  28.       # redirect server error pages to the static page /50x.html 
  29.       # 
  30.       error_page   500 502 503 504  /50x.html; 
  31.       location = /50x.html { 
  32.           root  /var/www/root/ng_finet230_cn; 
  33.       } 
  34.  
  35.       # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  36.       # 
  37.       #location ~ \.php$ { 
  38.       #    proxy_pass   http://127.0.0.1; 
  39.       #} 
  40.  
  41.       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  42.       # 
  43.       #location ~ \.php$ { 
  44.       #    root           html; 
  45.       #    fastcgi_pass   127.0.0.1:9000; 
  46.       #    fastcgi_index  index.php; 
  47.       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name
  48.       #    include        fastcgi_params; 
  49.       #} 
  50.  
  51.       # deny access to .htaccess files, if Apache’s document root 
  52.       # concurs with nginx’s one 
  53.       # 
  54.       #location ~ /\.ht { 
  55.       #    deny  all; 
  56.       #} 
  57.  
  58.       #將客戶端的請求轉交給fastcgi 
  59.       location ~ .*\.(php|php5|shtml)?$ { 
  60.           #root           html; 
  61.           fastcgi_pass   127.0.0.1:9000;#這里指定了fastcgi進程偵聽的端口,nginx就是通過這里與php交互的 
  62.           fastcgi_index  index.php; 
  63.           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name
  64.           include        fastcgi_params; 
  65.       } 
  66.  
  67.      #網(wǎng)站的圖片較多,更改較少,將它們在瀏覽器本地緩存30天 
  68.      location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 
  69.      { 
  70.        expires      30d; 
  71.      } 
  72.  
  73.      #網(wǎng)站會加載很多JS、CSS,將它們在瀏覽器本地緩存1小時 
  74.      location ~ .*\.(js|css)?$ 
  75.      { 
  76.        expires      1h; 
  77.      } 
  78.  
  79.   } 
  80.  
  81.  
  82.   # another virtual host using mix of IP-, name-, and port-based configuration 
  83.   # 
  84.   #server { 
  85.   #    listen       8000; 
  86.   #    listen       somename:8080; 
  87.   #    server_name  somename  alias  another.alias; 
  88.  
  89.   #    location / { 
  90.   #        root   html; 
  91.   #        index  index.html index.htm; 
  92.   #    } 
  93.   #} 
  94.  
  95.  
  96.   # HTTPS server 
  97.   # 
  98.   #server { 
  99.   #    listen       443; 
  100.   #    server_name  localhost; 
  101.  
  102.   #    ssl                  on; 
  103.   #    ssl_certificate      cert.pem; 
  104.   #    ssl_certificate_key  cert.key; 
  105.  
  106.   #    ssl_session_timeout  5m; 
  107.  
  108.   #    ssl_protocols  SSLv2 SSLv3 TLSv1; 
  109.   #    ssl_ciphers  HIGH:!aNULL:!MD5; 
  110.   #    ssl_prefer_server_ciphers   on; 
  111.  
  112.   #    location / { 
  113.   #        root   html; 
  114.   #        index  index.html index.htm; 
  115.   #    }  //Vevb.com 
  116.   #} 
  117.  
  118.   server 
  119.   { 
  120.     listen  8080; 
  121.     server_name  status.ng.finet230.cn; 
  122.  
  123.     location / { 
  124.       stub_status on; 
  125.       access_log   off; 
  126.     } 
  127.   } 

將/var/www/root/ng_finet230_cn目錄下的所有檔案與子目錄的擁有者皆設為www群體的使用者www:

[root@os11728 ~]# chown -R www:www /var/www/root/ng_finet230_cn

1.5.Nginx的啟動與關閉

啟動Nginx:

  1. [root@os11728 ~]# ulimit -SHn 65535 
  2. root@os11728 ~]# /usr/local/nginx/sbin/nginx 

停止Nginx:

  1.  [root@os11728 ~]# /usr/local/nginx/sbin/nginx -s stop 
  2. //或 
  3. [root@os11728 ~]# /usr/local/nginx/sbin/nginx -s quit 

重啟Nginx:

  1. [root@os11728 ~]# /usr/local/nginx/sbin/nginx -s reload 
  2. //或 
  3. [root@os11728 ~]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid` 

配置開機自動啟動Nginx + PHP,代碼如下:

[root@os11728 ~]# vi /etc/rc.local

在末尾增加以下內容:

  1. ulimit -SHn 65535 
  2. /usr/local/php/sbin/php-fpm 
  3. /usr/local/nginx/sbin/nginx

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 柘荣县| 韶关市| 新干县| 新余市| 奉化市| 仪征市| 乌恰县| 乐东| 抚松县| 长兴县| 正蓝旗| 阳高县| 黄陵县| 闵行区| 宜兰市| 城步| 密山市| 奈曼旗| 上林县| 元谋县| 鄢陵县| 张北县| 新平| 扎鲁特旗| 苏尼特右旗| 措勤县| 沂水县| 蓝田县| 精河县| 绵竹市| 威海市| 来宾市| 云南省| 清徐县| 青海省| 崇文区| 河间市| 肥城市| 中牟县| 大洼县| 蒙城县|