• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >Nginx > 指导:Ubuntu环境搭建nginx+php系统

指导:Ubuntu环境搭建nginx+php系统

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含ubuntu nginx php,ubuntu 安装nginx php,ubuntu下安装nginx,ubuntu nginx,ubuntu安装nginx等服务器相关知识,网友希望可以进行参考

 

指导:Ubuntu环境搭建nginx+php系统

 1,安装nginx,执行以下命令,很快完成,不过目前apg-get方式安装默认是0.5.33的版本

sudo apt-get install nginx

配置文件默认安装位置:

  [quote]conf: /etc/nginx/nginx.conf

  bin:/usr/sbin/nginx

  vhost: /etc/nginx/sites-enable/default

  cgi-params: /etc/nginx/fastcgi-params[/quote]

  建一个虚拟Server

  server {

  listen 80;

  server_name www.23day.com;

  access_log /var/log/nginx/home.ucenter.access.log;

  location / {

  root /var/www/23day.com;

  index index.php;

  location ~ \.php$ {

  fastcgi_pass 127.0.0.1:9000;

  fastcgi_index index.php;

  fastcgi_param SCRIPT_FILENAME /var/www/23day.com$fastcgi_script_name;

  include /etc/nginx/fastcgi_params;

  }

  }

  2,安装php-cgi模块执行sudo apt-get install php5-cgi 配置文件默认安装位置:

  php-cgi: /usr/bin/php-cgi

  php5-cgi: /usr/bin/php5-cgi

  cgi config: /usr/bin/cgi/php.ini [/quote]

修改php.ini文件的cgi.fix_pathinfo数据为1,默认为0 cgi.fix_pathinfo=1; 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量.

  3,安装spawn-fcgi spawn-fcgi是lighttpd的一个用来控制php-cgi的工具.

如果系统没有安装GCC编译环境,刚需要在安装lighttpd之前要安装build-essential工具包,执行以下命令

  sudo apt-get install build-essential

  wget http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz

  tar -xvf lighttpd-1.4.19.tar.gz

  cd lighttpd-1.4.19/

  sudo apt-get install libpcre3-dev

  ./configure –without-zlib –without-bzip2

  make

  sudo cp src/spawn-fcgi /usr/local/bin/spawn-fcgi

这样cgi控制器就安装完成.

  4.启动测试系统.启动fast_cgi:

  spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi

  注意:ip,端口与nginx服务器中的cgi-pass要对应. -C表示打开几个cgi进程

  启动nginx

  sudo /etc/init.d/nginx start

  好了,如果没有出错信息,则说明配置成功了,现在写个phpinfo测试下吧!

  最后,附上我的/etc/nginx/sites-enable/default的配置文件,此配置文件启用了rewrite功能

  server {

  listen 80;

  server_name localhost;

  access_log /var/log/nginx/localhost.access.log;

  location / {

  root /var/www/nginx-default;

  index index.php;

  if (-f $request_filename/index.html){

  rewrite (.*) $1/index.html break;

  }

  if (-f $request_filename/index.php){

  rewrite (.*) $1/index.php;

  }

  if (!-f $request_filename){

  rewrite (.*) /index.php;

  }

  }

  #error_page 404 /404.html;

  # redirect server error pages to the static page /50x.html

  #

  error_page 500 502 503 504 /50x.html;

  location = /50x.html {

  root /var/www/nginx-default;

  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80

  #

  #location ~ \.php$ {

  #proxy_pass http://127.0.0.1;

  #}

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

  #

  location ~ \.php$ {

  fastcgi_pass 127.0.0.1:9000;

  fastcgi_index index.php;

  fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;

  include /etc/nginx/fastcgi_params;

  }

  # deny access to .htaccess files, if Apache’s document root

  # concurs with nginx’s one

  #

  #location ~ /\.ht {

  #deny all;

  #}

  }

  # another virtual host using mix of IP-, name-, and port-based configuration

  #

  #server {

  #listen 8000;

  #listen somename:8080;

  #server_name somename alias another.alias;

  #location / {

  #root html;

  #index index.html index.htm;

  #}

  #}

  # HTTPS server

  #

  #server {

  #listen 443;

  #server_name localhost;

  #ssl on;

  #ssl_certificate cert.pem;

  #ssl_certificate_key cert.key;

  #ssl_session_timeout 5m;

  #ssl_protocols SSLv2 SSLv3 TLSv1;

  #ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

  #ssl_prefer_server_ciphers on;

  #location / {

  #root html;

  #index index.html index.htm;

  #}

  #}

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 指导:Ubuntu环境搭建nginx+php系统
  • Ubuntu下Nginx/PHP/MYSQL开发环境的配置方法

相关文章

  • IIS与Nginx实测对比[1]:虚拟机处理静态文件
  • 更换apache到nginx的操作过程全记录
  • Nginx下WordPress后台wp-admin不自动加斜杠的问题
  • Nginx开启Gzip压缩大幅提高页面加载速度
  • Nginx提示:413 Request Entity Too Large 的解决方法
  • nginx中隐藏响应头/返回头信息/php版本号/服务器信息
  • Nginx下统一顶级域名和www子域名实现自动转向
  • nginx location 指令匹配顺序
  • nginx静态压缩(ngx_http_gzip_static_module)
  • nginx 设置网站目录访问验证方法

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • Curl监控Nginx网站状态,如回应502信息即重启php-fpm
    • Nginx开启Gzip压缩大幅提高页面加载速度
    • Debian 7 安装LNMP服务器命令详解
    • Nginx怎么打开目录浏览功能(autoindex)
    • Nginx提示:413 Request Entity Too Large 的解决方法
    • nginx中隐藏响应头/返回头信息/php版本号/服务器信息
    • nginx 设置网站目录访问验证方法
    • nginx静态压缩(ngx_http_gzip_static_module)
    • Nginx 502 Bad Gateway错误的原因分析与解决方法
    • Nginx下WordPress后台wp-admin不自动加斜杠的问题

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有