nginx 支持php扩展,nginx运行无扩展名或非PHP扩展名文件的配置方法

要实现如上的功能,只需将nginx.conf文件中的默认 代码示例:

location ~ .

php$ {

…..

}

上的正则表达式 更改为: 代码示例:

location ~ (|.php)$ {

}

就可以了。

同理,也可以运行非.php扩展名的PHP文件,如 abc.html, abc.asp, abc.net, abc.jsp 等扩展名的PHP文件。

以上代码在php-5.2.17与nginx-0.8.54中调试通过。

附,nginx支持php的配置方法:

nginx安装及配置支持php的教程(2)

nginx安装及配置支持php的教程(1)

附,nginx.conf文件: 代码示例:

user  nobody;

worker_processes  1;

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {

worker_connections  1024;

}

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"';

#access_log  logs/access.log  main;

server_names_hash_bucket_size 64;

sendfile on;

tcp_nopush     on;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 120;

fastcgi_send_timeout 120;

fastcgi_read_timeout 120;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

gzip  on;

gzip_min_length  1k;

gzip_buffers     4 8k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

autoindex on;

server {

listen       8000;

server_name  www.#;

charset utf-8;

location / {

root   /opt/lzw/webapps;

index  index.php index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

location ~ (|.php)$ {

root           /opt/lzw/webapps;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

include        fastcgi_params;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值