十一 072015

Startssl 提供免费 SSL 证书,我们可以用其搭建 https 网站,过程简单记录如下:

1. 打开 http://www.startssl.com/ ,注册一个用户,注意这个网站是用证书验证用户身份的,所以证书一定备份好。
2. 登陆后进入 Validations Wizard,验证你要添加 ssl 支持的域名。
3. 进入 Certificates Wizard,并选择 Web Servers SSL/TLS Certificates。
4. 创建一个 private key,连同密码一起保管好。(也可以在服务器上用 openssl 创建,这里点skip就行了)
5. 选择一个域名,以及子域名。
6. 网站会给出证书,保存为 .csr 文件。
7. 使用 Tool Box 里面的 Decrypt Private Key 或者用 openssl 将第4步生成的 private key 解密,并将结果保存为 .key 文件。 Continue reading »

LNMP安装Fancy Index

Posted by 冰河 at 16:05 No Responses » 9,306 Views
132015

1.安装LNMP
下载版:http://soft.vpser.net/lnmp/lnmp0.9.tar.gz  (46.45KB)
完整版:http://soft.vpser.net/lnmp/lnmp0.9-full.tar.gz  (61.83MB)
MD5:0eb79ddd5cd1df3a487f62e7943aaa9d

安装步骤:
1)使用putty登陆VPS或服务器;
登陆后运行:screen -S lnmp
如果提示screen: command not found 命令不存在可以执行:yum install screen安装。

2)下载并安装LNMP一键安装包:
安装LNMP执行:wget -c http://soft.vpser.net/lnmp/lnmp0.8-full.tar.gz?&& tar zxf lnmp0.8-full.tar.gz && cd lnmp0.8-full && ./centos.sh

2.升级Nginx
upgrade_nginx.sh,选1.6.2

3.下载fancyindex
git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex

4.重新编译Nginx

/usr/local/nginx/sbin/nginx -V #查看nginx已经编译参数

cd nginx-1.6.2
make clean
./configure --add-module=../ngx-fancyindex  [extra desired options](上面的Nginx已经编译参数)
make
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-1.6.2
cp objs/nginx /usr/local/nginx/sbin

Continue reading »

128MB小内存VPS安装LNMP

Posted by 冰河 at 18:59 2 Responses » 44,839 Views
302012

买了个128MB内存的VPS,想装WordPress折腾下。软件当然首选LNMP,系统尝试了几次还是选Debian。话说高配置的机器还是推荐Centos,文档多,出了问题也好解决。但是像128MB内存的机器还是Debian省资源。

从lnmp.org下了一键安装包。可是尝试无数次都失败。最后看log发现是mysql安装失败。nginx和php都编译并安装,唯独mysql编译的时候out of memory了。于是想用一键安装包的脚本安装nginx和php等软件,mysql用apt-get安装。研究下了一键安装脚本,发现过于繁琐,虽然lnmp.org提供的一键安装包省事而且也能提高网站的访问体验,但是系统开销是很大的。

找来找去无意中看到了一个很神奇的脚本lowendbox的lowendscript。研究下了果断决定用这个脚本安装。

下面是LEB脚本包含的软件和对系统的修改
安装/替换的软件

dropbear to replace openssh. Invoked from xinetd.
inetutils-syslogd to replace rsyslog.
exim4 to replace sendmail (if installed). Re-configured to allow Internet delivery.
cron
nginx
mysql. Re-configured to remove innodb support, remove query cache and reduce key buffer size.
php with built-in FastCGI interface. Running only 1 child process and respawn after 5,000 requests.

对系统/软件的修改:

Removing some commonly bundled applications that should not be there in the first place for a minimal distro (apache2, sendmail, bind9, samba, nscd, etc).
MySQL root is given a new password (which can be found in ~root/.my.cnf)
Installing each WordPress site under /var/www/. It will create appropriate database, users and password for the site. Continue reading »

Nginx多站点设置

Posted by 冰河 at 21:51 1 Response » 36,069 Views
十二 182009

方法一:多个.conf方法(优点是灵活,缺点就是站点比较多配置起来麻烦)

这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:

IP地址: 202.55.1.100
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2

配置 nginx virtual hosting 的基本思路和步骤如下:

把2个站点 example1.com, example2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 example1.com.conf,example2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx

具体过程

下面是具体的配置过程:

1、在 /etc/nginx 下创建 vhosts 目录

mkdir /etc/nginx/vhosts

2、在 /etc/nginx/vhosts/ 里创建一个名字为 example1.com.conf 的文件,把以下内容拷进去

server {
        listen  80;
        server_name  example1.com www. example1.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root   /www/example1.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # 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  /www/example1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /.ht {
            deny  all;
        }
}

3、在 /etc/nginx/vhosts/ 里创建一个名字为 example2.com.conf 的文件,把以下内容拷进去

server {
        listen  80;
        server_name  example2.com www. example2.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root   /www/example2.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # 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  /www/example2.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /.ht {
            deny  all;
        }
}

4、打开 /etc/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来

user  nginx;
worker_processes  1;

# main server error log
error_log	/var/log/nginx/error.log ;
pid	/var/run/nginx.pid;

events {
	worker_connections  1024;
}

# main server config
http {
	include       mime.types;
	default_type  application/octet-stream;
	log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

	sendfile        on;
	#tcp_nopush     on;
    	#keepalive_timeout  0;
	keepalive_timeout  65;
	gzip  on;

	server {
        	listen         80;
        	server_name     _;
        	access_log      /var/log/nginx/access.log main;
        	server_name_in_redirect  off;
        	location / {
            		root  /usr/share/nginx/html;
            		index index.html;
        	}
	}

    # 包含所有的虚拟主机的配置文件
    include /usr/local/etc/nginx/vhosts/*;
}

5、重启 Nginx

/etc/init.d/nginx restart

方法二:动态目录方法(优点是方便,每个域名对应一个文件夹,缺点是不灵活)

这个简单的方法比起为每一个域名建立一个 vhost.conf 配置文件来讲,只需要在现有的配置文件中增加如下内容:

# Replace this port with the right one for your requirements
# 根据你的需求改变此端口
listen       80;  #could also be 1.2.3.4:80 也可以是1.2.3.4:80的形式
# Multiple hostnames seperated by spaces.  Replace these as well.
# 多个主机名可以用空格隔开,当然这个信息也是需要按照你的需求而改变的。
server_name  star.yourdomain.com *.yourdomain.com http://www.*.yourdomain.com/;
#Alternately: _ *
#或者可以使用:_ * (具体内容参见本维基其他页面)
root /PATH/TO/WEBROOT/$host;
error_page  404              http://yourdomain.com/errors/404.html;
access_log  logs/star.yourdomain.com.access.log;
location / {
root   /PATH/TO/WEBROOT/$host/;
index  index.php;
}
# serve static files directly
# 直接支持静态文件 (从配置上看来不是直接支持啊)
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log        off;
expires           30d;
}
location ~ .php$ {
# By all means use a different server for the fcgi processes if you need to
# 如果需要,你可以为不同的FCGI进程设置不同的服务信息
fastcgi_pass   127.0.0.1:YOURFCGIPORTHERE;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /PATH/TO/WEBROOT/$host/$fastcgi_script_name;
fastcgi_param  QUERY_STRING     $query_string;
fastcgi_param  REQUEST_METHOD   $request_method;
fastcgi_param  CONTENT_TYPE     $content_type;
fastcgi_param  CONTENT_LENGTH   $content_length;
fastcgi_intercept_errors on;
}
location ~ /.ht {
deny  all;
}

最后附另外一个二级域名匹配的方法

绑定域名
server_name *.abcd.com;
获取主机名
if ( $host ~* (.*).(.*).(.*))
{
set $domain $1;
}
定义目录
root html/abc/$domain/;
location /
{
root html/abcd/$domain;
index index.html index.php;

Nginx PHP No input file specified

Posted by 冰河 at 21:45 No Responses » 24,524 Views
十二 182009

刚装好Nginx,马上加了个 PHPINFO

  1. <?php
  2. phpinfo();
  3. ?>

然后在游览器下运行 结果是

No input file specified.

以下内容为网络收集

FastCGI模式下访问php文件时,出现No input file specified.错误
查看access.log 发现是 404

原因分析:
任何对.php文件的请求,都简单地交给php-cgi去处理,但没有验证该php文件是否存在。PHP文件不存在,没办法返回普通的404错误,它返回一个404,并带上一句”No input file specified”

另外,还可能跟 路径或者 权限有关系,或者SCRIPT_FILENAME 变量没有被正确的设置(这在nginx是最常见的原因)

1)如果html也出现404错误,那么就是document root 设置的有问题
2)检查脚本文件的权限, 可能PHP或者web server不能读取它
3)SCRIPT_FILENAME设置错误

可以使用
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
必须保证 $document_root 在配置文件中,在astcgi_param SCRIPT_FILENAME前面被用到过一次, 后面有解释为什么。

或者
修改/etc/php5/cgi/php.ini中cgi.fix_pathinfo=1
这样也可让php-cgi正常使用SCRIPT_FILENAME这个变量

有人说,这样改也行
fastcgi_param SCRIPT_NAME /home/gavin/nginx/$fastcgi_script_name;

让我们看看PHP对这两个变量是怎么解释的吧
SCRIPT_NAME
SCRIPT_FILENAME
据说,必须指定正确的SCRIPT_FILENAME, PHP-CGI会忽略SCRIPT_NAME(即使它的值设置的是正确的)
或者指定特殊的php.ini, 设置doc_root, discard path, fix pathinfo等等

script_filename 只是被用做一种快捷方式。 如果fix_pathinfo设置打开,init函数将它用来决定真实的路径

因为配置文件会改变 nginx的变量$fastcgi_script_name

fastcgi_param SCRIPT_NAME /home/gavin/nginx/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME /home/gavin/nginx/$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

这两种配置都是可以的


fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
也是可以的,但必须保证 $document_root 被正确设置过

‘SCRIPT_FILENAME’
当前执行脚本的绝对路径名(pathname)
‘SCRIPT_NAME’
含有当前脚本的路径。当页面需要指向他们自己时,有用. __FILE__ 常量包含路径和文件名

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP’s
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix it’s paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; cgi.fix_pathinfo=0

主要跟CGI标准的
PATH_INFO
PATH_TRANSLATED
SCRIPT_NAME
有关系
修修改了好多
最终主要修改的

把 NGINX DEFAULT 那个文件中的

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

改成实际的路径

今天我是这种情况

我的是fastcgi_param SCRIPT_NAME /var/www/nginx-default/$fastcgi_script_name;

然后就好了
上面的文章供参考
如果试了还不行 多看看内容再试试

Nginx负载均衡

Posted by 冰河 at 20:33 No Responses » 6,108 Views
十二 182009

nginx是什么?

Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。

首先是配置十分的简单,而且功能非常强大。真是相见恨晚。
先来看看配置文件怎么写吧

worker_processes 1;
events {
worker_connections 1024;
}
http{
upstream myproject {
#这里指定多个源服务器,ip:端口,80端口的话可写可不写
server 192.168.43.158:80;
server 192.168.41.167;
}

server {
listen 8080;
location / {
proxy_pass http://myproject;
}
}
}

nginx的负载均衡有哪些功能呢?
[list]
[*]如果后面的服务器其中一台坏了,它能自动识别,更牛的是它好了之后nginx可以马上识别
[*]服务器A和B,如果A的响应时间为3,B的响应时间为1,那么nginx会自动调整访问B的概率是A的3倍,真正做到负载均衡
[/list]

在这里还是想说说nginx的安装及运行
先到http://www.nginx.net/下载最新的源码包。
我下载到的是nginx-0.5.33.tar.gz
解压:tar zxvf nginx-0.5.33.tar.gz
接着:./configure
再接着:make
最后:make install
好的,安装完成了。我在make的时候报了个错,说HTTP Rewrite 模块 有问题,我就./configure –without-http_rewrite_module
然后再make,make install就可以了。
安装好了之后新建一个配置文件,把上面的配置文件内容拷进去,当然要修改你的IP,保存为比如 load_balance.conf

然后启动:
/usr/local/nginx/sbin/nginx -c load_balence.conf

如果上面的步骤走下来有问题的话,可以参考:
nginx的中文维基

http://wiki.codemongers.com/NginxChs

当然也可以到官方网站
www.nginx.net
www.nginx.com

由于nginx的作者是俄国人,所以英文的文档也不是那么完善,对于我来说nginx的最大优点还是配置简单,功能强大
apache-jk配起来太复杂了,而且只能用来做tomcat的负载均衡。
nginx就没有这个限制,对它来说后面是什么服务器是完全透名的。

© 2009 - 2024 冰河的博客