Linux下nginx配置虚拟主机

在弄到新服务器,安装了所有东西后,开始配置新的站点测试了,可是问题却随之而来呀,主要是站点设置成功,但是并不支持php。
nginx配置站点其实就是基于一ip多站点。
那么在配置目录中新建一个配置文件,名字起得和站点名字相同,然后写入:

server {
    listen       80;
    server_name www.piyaoyan.com piyaoyan.com;
    access_log  /var/log/nginx/piyaoyan.com/access.log  main;
    root   /home/akcms/domains/piyaoyan.com/www;
    index  index.html index.htm index.php;
 
    rewrite ^/$ /akcms_item.php?id=1 last;
    rewrite ^/rss.xml$ /akcms_item.php?id=6 last;
    rewrite ^/index.html$ /akcms_item.php?id=1 last;
    rewrite ^/index-([0-9]+).htm$ /akcms_item.php?id=1&page=$1 last;
    rewrite ^/index-([0-9]+).html$ /akcms_item.php?id=1&page=$1 last;
    rewrite ^/yaoyan/([0-9]+).html$ /akcms_item.php?id=$1 last;
    rewrite ^/category/([0-9]+)\.html$ /akcms_category.php?id=$1 last;
    rewrite ^/category/([0-9]+)\-([0-9]+)\.html$ /akcms_category.php?id=$1&page=$2 last;
 
 
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

在这个配置中写了伪静态的规则,支持php是下面这一条location ~\.pjp$。
写完配置后检测nginx的配置是否正确,使用nginx -t 然后重启nginx ,使用nginx -s reload
在浏览器中访问,看看是否可以,是否支持php.
好,不支持,那么这就要修改phpfastcgi的配置了,使用ps -ef | grep php
找到该服务,看看它的配置文件在什么地方,然后编辑一下。
在这里我们需要修改pool的用户和组用户,修改为和配置文件对应的用户和组即可。
重启这个玩意,重启它有点麻烦,还得通过pid来重启:kill -USR2 pid(就是主进程id)重启该服务。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。