您的位置:首页 > 运维架构 > Nginx

nginx虚拟机配置(支持php)

2015-06-25 19:04 274 查看
由于本人水平有限,以下记录仅作参考。

下面贴出我的一份正常运行的nginx服务器虚拟机配置。/usr/local/nginx/conf/vhost/www.xsll.com.conf

server {
listen       80;              #虚拟主机监听端口
server_name  www.xsll.com;        #虚拟主机名称

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

root  /home/wwwroot/default/discuz/upload;  #你的项目目录
index index.php index.html index.htm;     #默认寻找的文件

location / {
try_files $uri $uri/ =404;
if (!-e $request_filename){
rewrite ^/(.*)?$ /$1.php?last;
  }
}

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   /usr/share/nginx/html;
}

# 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$ {
#root          html;
try_files      $uri = 404;
fastcgi_pass   unix:/tmp/php-cgi.sock;  #这一行很重要,路径要与PHP配置文件中的监听路径相同,但前面要加unix:/
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME  /scripts$fastcgi_script_name;
include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}


下面我贴出我的php的配置文件/user/local/php/etc/php-fpm.conf

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log


可以看到在虚拟主机配置的38行:fastcgi_pass unix:/tmp/php-cgi.sock;这个路径正式php配置文件中第7行:listen = /tmp/php-cgi.sock;这样nginx虚拟机就支持了PHP程序解析了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: