LNMP之nginx的基本配置
来源:互联网 发布:游族网络 刀剑乱舞 编辑:程序博客网 时间:2024/05/21 19:44
注:nginx 的nginx.conf文件中 listen监控的端口要和 php-fpm listen的监控端口一致,这样就没有502的问题。
1.Nginx用户认证
location ~ .*admin\.php {
auth_basic "eric auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
2.域名跳转301/302重定向
server_name www.test.com www.aaa.comwww.bbb.com
if (host !='www.test.com'){
rewrite ^/(.*)$ http://www.test.com/$1 permanet;
}
3.不记录指定了类型文件日记
location ~ .*\.(gif|jpg|jpeg|swf)
{
access_log off;
}
location ~ (static|cache)
{
access_log off;
}
4.日记切割
vim /usr/local/sbin/nginx_logrotate.sh
----------------
#!/bin/bash
d= `date -d "-1 day" +%F`
[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log/
mv /tmp/access.log /tmp/nginx_log/$d.log
/etc/init.d/nginx restart > /dev/null
cd /tmp/nginx_log/
gzip -f $d.log
执行脚本
sh -x /usr/local/sbin/nginx_logrotate.sh
5.设置文件失效时间
location ~ .*\.(gif|jpg|jpeg|rar|png)$
{
access_log off;
expires 2h;
}
6.防盗链配置
location ~ .*\.(gif|jpg|jpeg|rar|png|rar|zip|flv|mp3)$
{
access_log off;
expires 2h;
valid_referers none blocked *.test.com *.aaa.com *.aminglinux.com;
if ($invalid_referer)
{
return 403;
}
}
7.nginx 访问控制
黑名单
deny 127.0.0.1
白名单
allow 192.168.141.133
deny all
某个文件夹下实现访问控制
location ~ .*\.admin.php
{
allow 192.168.141.133
deny all
auth_basic "eric auth"
auth_basic_user_file /usr/local/nginx/conf/.htpasswd
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
8.禁止指定user_agent
if ($http_user_agent ~ 'curl|baidu|1111')
{
return 403;
}
9.Nginx反向代理
譬如代理www.baidu.com
首先ping出百度的ip
其次在nginx虚拟主机文件夹下编辑配置文件
vim /usr/local/nginx/conf/vhost/proxy.conf
server
{
listen 80;
server_name www.baidu.com;
location /{
proxy_pass http://'插入百度IP/';
proxy_set_header Host $host;
}
}
负载均衡写法:
upstream eric{
server xxxxxx;
server xxxxx ;
}
server
{
listen 80;
server_name www.baidu.com;
location /{
proxy_pass http://eric/';
proxy_set_header Host $host;
}
}
1 0
- LNMP之nginx的基本配置
- nginx之LNMP配置知识
- 【Nginx】LNMP环境下的后续配置
- lnmp开发laravel的nginx配置
- lnmp配置nginx
- lnmp架构之nginx的安装
- LNMP环境的搭建及基本配置
- lnmp之nginx
- Linux---lnmp之nginx
- lnmp 之nginx安装
- web服务器之LNMP(1)Ubuntu中Nginx的安装与配置
- Nginx的基本配置
- nginx的基本配置
- nginx 的基本配置
- nginx的基本配置
- nginx的基本配置
- Nginx的基本配置
- Linux下安装Lnmp环境之Nginx Vhosts配置
- webview加载网页空白或者不全的问题
- OceanBase
- EDIUS设置Alpha转场的方法
- 计算分数精确值
- thinkphp5数据库操作方法小结
- LNMP之nginx的基本配置
- CocoaChina(总结)升级到xcode8遇到的问题及解决方案
- LA 4270 Discrete Square Roots
- js Math.ceil()、Math.floor()和Math.round()
- Android APP崩溃上传日志到服务器并且重启!
- mysql 容灾 灾备 备份
- loadrunner运行脚本提示:You do not have a licence for this Vuser type......
- Java设计模式一
- PHP搭建自己的MVC框架9 配置加载类