httpd nginx php配置文件,apache+nginx虚拟主机总配置文件

#server定义一个虚拟主机

server

{

listen 80;

#网站的域名,可以有多个

server_namewww.123.com www.abc.com;

#301域名重定向

if ($host != 'www.123.com')

{

rewrite ^/(.*)$ http://www.123.com/$1 permanent;

}

index index.htmlindex.htm index.php;

#网站根目录

root /data/www;

#访问日志存放路径,aming为日志的格式,自己定义,在nginx配置文件

access_log/tmp/access.log aming;

#访问控制,对于外部控制,越精确越优先匹配

#deny 127.0.0.1;

#插入一个文件

#include deny.sh;

#用户认证管理后台

location ~.*admin\.php$ {

#访问控制

#allow 127.0.0.1;

#deny all;

#用户认证是通过apache的htpasswd工具

#auth_basic "tingshi";

#auth_basic_user_file /usr/local/nginx/conf/.htpasswd;

#nginx和php-fpm通信的方式,解析php脚本

include fastcgi_params;

fastcgi_pass unix:/tmp/php-fcgi.sock;

fastcgi_index index.php;

#解析php的根目录

fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|rar|zip|bz2)$

{

#gif|jpg|png等静态文件过期时间

expires      30d;

#不记录gif|jpg|png等格式访问日志

access_log off;

#图片,音乐等防盗链

valid_referers none blocked*.123.com *.abc.com;

if ($invalid_referer)

{

return 403;

}

}

location ~ .*\.(js|css)

{

#js|css静态文件过期时间

expires      12h;

#不记录js|css等格式访问日志

access_log off;

}

location ~\.php$ {

#nginx和php-fpm通信的方式,解析php脚本

include fastcgi_params;

fastcgi_pass unix:/tmp/php-fcgi.sock;

#fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#解析php的根目录

fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

}

#禁止指定的user_agent(搜索引擎)

#if ($http_user_agent  ~*'curl|baidu|youdao')

#    {

#        return 403;

#    }

}

#简单虚拟主机

server

{

listen 80;

server_name www.woo.com;

index index.html index.htm index.php;

root /data/wordpress;

location ~ \.php$ {

include fastcgi_params;

fastcgi_pass unix:/tmp/php-fcgi.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /data/wordpress$fastcgi_script_name;

}

}

#nginx扩展

Nginx禁止某个目录解析php

location ~ .*abc/.*\.php?$

{

deny all;

}

Nginx禁止访问.txt文件

location ~* \.(txt|doc)$ {

if (-f $request_filename) {

root/home/domain/public_html/test;

break;

}

}-

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值