`
xulei3244
  • 浏览: 13960 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

about nginx

阅读更多
1.安装nginx
运行:
sudo apt-get intsall nginx
Ubuntu安装之后的文件结构大致为:
* 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
* 程序文件在/usr/sbin/nginx
* 日志放在了/var/log/nginx中
* 并已经在/etc/init.d/下创建了启动脚本nginx




* 默认的虚拟主机的目录设置在了/var/www/nginx-default
下面可以启动nginx来看看效果(请确保80端口没有其他服务在使用):
Ubuntu请运行:
sudo /etc/init.d/nginx start
然后打开浏览器,查看http://localhost/ 看看是否看到了“Welcome to nginx!” 如果看到了,说明安装成功。当然,基本上,这块儿都不会出问题。
如果运行不成功,可以先 sudo killall apache2 杀掉apache进程
2.安装php:
当然,现在我们都用php5了。运行:
sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl

3.安装spawn-fcgi
运行sudo apt-get install spawn-fcgi
为什么要安装spawn- fcgi呢,它用来控制php-cgi进程,以防止进程崩溃或是单进程的效率太低。
网上很多人都说要使用spawn-fcgi必须得安装 lighttpd,实际上不必要,可以直接安装spawn-fcgi

接下来就是最让人头疼的配置。
配置Nginx和spawn-fcgi配合运行
(1).在/etc/nginx /fastcgi_params 文件最后,加入一行,可以用sudo gedit /etc/nginx/fastcgi_params打开文件
加入此行:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

(2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位于/etc/php5/cgi/php.ini)中,找到cgi.fix_pathinfo选项,修改为:
cgi.fix_pathinfo=1;
这样php-cgi方能正常使用SCRIPT_FILENAME这个变量。

(3).打开/etc/nginx/sites-available/default文件

server {
listen 80;
server_name localhost;

下面添加
root /var/www/nginx-default
即root和server_name同级
这段即相当于 apache的默认目录 如果没有这个的话,容易在执行php 文件的时候,会提示”No input file specified”。我就曾在此绕了好大个圈子才发现问题。

然后修改
#location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#includefastcgi_params;
#}

修改成

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; #fastcgi的参数文件地址
}

然后运行
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
来启动fast-cgi进程,然后我们可以将这行代码加入到/etc/rc.local文件底部,这样系统启动的时候也可以同时启动PHP的FastCGI 进程。

再运行sudo /etc/init.d/nginx restart 重启nginx
好了,可以把你的php文件放在/var/www /nginx-default下面来测试一下了。

如果打开php文件出现:No input file specified
请检查
php.ini的配置中
cgi.fix_pathinfo=1
doc_root=
还有,每个虚机要根据自己不通的虚机设置不能的目录,要保证这个路径正确。
检查/etc/nginx/sites-available下的配置文件中,server内包含 root 及地址 而非location内的root

附重启nginx和php-cgi 的命令

nginx: sudo /etc/init.d/nginx restart 同样也可以有start,stop等参数
php-cgi: 先杀死进程
sudo killall -HUP php5-cgi
再启动
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

参数含义如下

* -f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
* -a 绑定到地址addr
* -p 绑定到端口port
* -s 绑定到unix socket的路径path
* -C 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
* -P
指定产生的进程的PID文件路径
* -u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等
———————————-
如果要安装 zendOptimizer
先去zend官网下载,地址http://www.zend.com/en/products/guard /downloads
找对应你操作系统的zendOptimizer,如果下载过程中要求注册,而你没有注册过,那就不防注册一次,一劳永逸。
然后解压,打开data文件夹,再找出对应你php版本的so文件。基本上现在都是php5.2了,所以在 5_2_x_comp/ZendOptimizer.so
可以把这个文件放在任何位置,只要在php.ini中指定出绝对位置就行。
比如我们将其放在/usr/local下面。
sudo mkdir /usr/local/zend //按提示输入密码
在你解压出的文件夹内,执行
sudo cp ZendOptimizer.so /usr/local/zend
将这个文件拷过去。
编辑 php.ini ,在终端输入
sudo gedit /etc/php5/cgi/php.ini
在文件末尾加入
[Zend Optimizer]
zend_optimizer.optimization_level=1
zend_extension=”/usr/local/zend/ZendOptimizer.so”

然后重启fastcgi
sudo killall -HUP php5-cgi
再启动
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
OK了。用php探针看看吧。
4、安装 PHP和MySQL
sudo apt-get install mysql-server mysql-client
中间会提示输入 Root用户密码,依次输入即可。

启动MySQL
sudo /etc/init.d/mysql start

mysql -uroot -p
输入mysql密码
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
+——————–+
mysql 已正确安装了。

分享到:
评论

相关推荐

    Something About Nginx

    Something About Nginx

    nginx 官方cookbook

    This book is about NGINX the web server, reverse proxy, load balancer, and HTTP cache. Part I will focus mostly on the load-balancing aspect and the advanced features around load balancing, as well ...

    Nginx-Essentials.pdf

    After trying and rejecting a number of options, I came to know about Nginx and immediately felt that my search was over. It is small yet powerful, with a clean code base, good extensibility, relevant ...

    Mastering-Nginx.pdf

    Feel free to jump in anywhere you feel you need to get more in-depth about a particular topic. If you feel you have missed something major, go back and read the earlier chapters. They are constructed...

    Nginx-Index索引页面

    <a href="about.html">关于我 联系我们 ``` **Nginx配置调整** 要启用自定义的`Nginx-Index`页面,你需要确保配置文件指向正确的文件路径。例如,如果你的自定义页面是`custom_index.html`,则配置如下: ```...

    Nginx From Beginner to Pro(Apress,2016)

    Once you are fully comfortable with Nginx, you will start learning about migrating applications (or its part) from IIS or Apache web servers. Finally, you will learn to troubleshoot and maintain your...

    complete_nginx_cookbook.pdf

    How to configure content caching, load balancing, monitoring, high availability (HA), and other critical NGINX features. ...About monitoring and troubleshooting application performance with NGINX.

    Nginx高性能WEB服务器系列(超级详细)

    ### Nginx 高性能 WEB 服务器系列知识点详解 #### 1. Nginx 入门简介 **Nginx** 是一款广受欢迎的高性能 HTTP 和反向代理服务器,同时也可作为 IMAP/POP3/SMTP 代理服务器。它以其出色的稳定性、丰富的功能集、...

    蚂蚁伪静态5.9nginx

    ### 蚂蚁伪静态5.9 Nginx配置解析 #### 一、概述 本文主要解析了“蚂蚁伪静态5.9nginx”的Nginx配置规则,该配置旨在优化网站URL结构,使其更加友好、易于记忆且有利于搜索引擎优化(SEO)。通过一系列重写规则,...

    nginx-vhosts:以编程方式向正在运行的 Nginx 实例添加或删除虚拟主机

    }配置了 about 的机器将使用/etc/nginx/conf.d/或/etc/nginx/sites-enabled/作为下面的confDir 。 请注意,Nginx 的官方默认以这种方式配置。 也可以看看: 接口var vhosts = require('nginx-vhosts')(opts,

    nginx配置location时容易出现的误区

    ### Nginx 配置 Location 时常见的误区详解 在 Nginx 的配置过程中,`location` 是一个非常重要的概念,用于控制特定 URL 模式的请求处理方式。然而,在实际应用中,不少开发者对 `location` 的理解存在一定的误区...

    echo-nginx-module:Nginx模块,用于将“ echo”,“ sleep”,“ time”等功能引入Nginx的配置文件

    姓名 ngx_echo-为Nginx配置文件带来“ echo”,“ sleep”,“ time”,“ exec”和更多shell样式的东西。 该模块不随Nginx源一起分发。 请参阅。... echo "'hello world' takes about $echo_timer_elapse

    AIO nginx C10K

    something about highest Asynchronous Performance development of Concurrent, may be the best docs you can find , thanks

    nginx-lua-static-merger:基于openresty的静态文件合并

    About 详细教程请看: nginx-lua-static-merger是一个基于openresty的模块,主要用于合并静态文件,减少http请求,加快静态文件访问速度的模块。 使用nginx-lua-static-merger 需要在编译nginx时候添加openresty的...

    一文弄懂Nginx的location匹配的实现

    “documents/about.html”会匹配到配置B。 此外,@符号用于定义一个命名的location,主要应用于内部重定向场景,不能用于处理正常的外部请求。例如,可以在配置中使用try_files指令配合命名location来处理文件找不...

    ubuntu14.04LTS安装nginx+mariaDB+php7+YAF的方法

    本文讲述了ubuntu14.04LTS安装nginx+...in order to authenticate the nginx repository signature and to eliminate warnings about missing PGP key during installation of the nginx package, it is necessary to

    weixin_robot_vhelper:基于nginx_lua的微信机器人

    About微信公共账号 “V哥助手” 基于nginx lua开发,通过整合开放数据平台API实现如下功能:天气查询人脸检测智能听歌智能查书智能翻译RequirementsInstallation下载vhelper, 执行install.sh(自动下载所有依赖库)...

    docker快速构建disconf镜像

    de596887acac conf_nginx:0.0.1 "nginx -g 'daemon ..." About an hour ago Up About an hour 0.0.0.0:80->80/tcp dockerdisconfmaster_disconf_nginx_1 5bbdb21bf496 conf_tomcat:0.0.1 "catalina.sh run" About an...

Global site tag (gtag.js) - Google Analytics