这几天在搭建LNMP 环境,环境是已经搭建好了,但nginx 有些具体的配置还需要添加,目录权限限制 这个搞了我两天,在论坛、百度搜索、都有试过,搜索的结果大同小异,都是很简单,但是真用到生产环境中,就不行了(可能和我的其他配置有关系),还有就是网上搜索到的技术配置都一小段,根本就行不通,原因是有些配置文件是分前后关系的,所以我把真实的配置文件及配置顺序贴出来。 这个目录权限问题,最后还是找的铭哥解决掉的,
server
2 {
3 listen 80;
4 server_name www.chao.com;
5 index index.html index.htm index.php;
6 root /data/www/html;
7 # root /usr/local/nginx/html;
8
9 access_log /tmp/nginx_access.log ycx;
10
11
12 if (!-e $request_filename) {
13 rewrite ^/(.*)/*$ /index.php/$1 last;
14 break;
15 }
16
17
18
19 if ($http_user_agent ~* 'alibaba') {
20 return 403;
21 }
22
23
24
25 location ~ .*\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ {
26 expires 30d;
27 valid_referers none blocked *.v5cg.com ;
28
29 if ($invalid_referer) {
30 return 403;
32 }
33 access_log off;
34 }
35
36
37
38 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
39 expires 10d;
40 access_log off;
41 }
42
43 location ~ .*\.(js|css)?$ {
44 expires 2h;
45 access_log off;
46 }
47
48 location ~ /admin/ {
49 allow 127.0.0.1;
50 allow 192.168.1.130;
51 deny all;
52
53 location ~ \.php {
54 include fastcgi_params;
55 fastcgi_pass unix:/tmp/php-fcgi.sock;
56 fastcgi_index index.php;
57 fastcgi_split_path_info ^(.+\.php)(.*)$;
58 fastcgi_param PATH_INFO $fastcgi_path_info;
59 fastcgi_param SCRIPT_FILENAME /data/www/html$fastcgi_script_name;
60 }
61 }
62
63
66 location ~ \.php {
67 include fastcgi_params;
68 fastcgi_pass unix:/tmp/php-fcgi.sock;
69 fastcgi_index index.php;
70 fastcgi_split_path_info ^(.+\.php)(.*)$;
71 fastcgi_param PATH_INFO $fastcgi_path_info;
72 fastcgi_param SCRIPT_FILENAME /data/www/html$fastcgi_script_name;
73 # fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
74 }
76 }
上面这些配置都是生产环境中的,我说说自己试过的结果 ,没有蓝色字体的,测试出来的结果是两个只能有一个生效,要不就是目录重写生效 权限失效,另外一个是权限生效 重写失效,所以搞了两天都没有成功,最后我这边是没有希望了,最后的希望寄托到铭哥身上了,当天就处理好了,所以有些东西还是需要在生产工作中实践。
由于自己学的不怎么好,很多都东西到了工作都记不得了,出错的地方也很多,很感谢铭哥这个平台。
说说公司的环境 吧
公司是一个新公司,有20人,做CG行业的一个平台(公司网站www.v5cg.com), 最新在做客户端上线项目,之前公司服务器是win下,现在要迁移到Linux环境下,运维 就我一个人,后面还有很事情要做。 现在主要的是网站的传输加密 ,需要我这边来处理目前还不有头绪,有知道同学请留言。
server
2 {
3 listen 80;
4 server_name www.chao.com;
5 index index.html index.htm index.php;
6 root /data/www/html;
7 # root /usr/local/nginx/html;
8
9 access_log /tmp/nginx_access.log ycx;
10
11
12 if (!-e $request_filename) {
13 rewrite ^/(.*)/*$ /index.php/$1 last;
14 break;
15 }
16
17
18
19 if ($http_user_agent ~* 'alibaba') {
20 return 403;
21 }
22
23
24
25 location ~ .*\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ {
26 expires 30d;
27 valid_referers none blocked *.v5cg.com ;
28
29 if ($invalid_referer) {
30 return 403;
32 }
33 access_log off;
34 }
35
36
37
38 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
39 expires 10d;
40 access_log off;
41 }
42
43 location ~ .*\.(js|css)?$ {
44 expires 2h;
45 access_log off;
46 }
47
48 location ~ /admin/ {
49 allow 127.0.0.1;
50 allow 192.168.1.130;
51 deny all;
52
53 location ~ \.php {
54 include fastcgi_params;
55 fastcgi_pass unix:/tmp/php-fcgi.sock;
56 fastcgi_index index.php;
57 fastcgi_split_path_info ^(.+\.php)(.*)$;
58 fastcgi_param PATH_INFO $fastcgi_path_info;
59 fastcgi_param SCRIPT_FILENAME /data/www/html$fastcgi_script_name;
60 }
61 }
62
63
66 location ~ \.php {
67 include fastcgi_params;
68 fastcgi_pass unix:/tmp/php-fcgi.sock;
69 fastcgi_index index.php;
70 fastcgi_split_path_info ^(.+\.php)(.*)$;
71 fastcgi_param PATH_INFO $fastcgi_path_info;
72 fastcgi_param SCRIPT_FILENAME /data/www/html$fastcgi_script_name;
73 # fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
74 }
76 }
上面这些配置都是生产环境中的,我说说自己试过的结果 ,没有蓝色字体的,测试出来的结果是两个只能有一个生效,要不就是目录重写生效 权限失效,另外一个是权限生效 重写失效,所以搞了两天都没有成功,最后我这边是没有希望了,最后的希望寄托到铭哥身上了,当天就处理好了,所以有些东西还是需要在生产工作中实践。
由于自己学的不怎么好,很多都东西到了工作都记不得了,出错的地方也很多,很感谢铭哥这个平台。
说说公司的环境 吧
公司是一个新公司,有20人,做CG行业的一个平台(公司网站www.v5cg.com), 最新在做客户端上线项目,之前公司服务器是win下,现在要迁移到Linux环境下,运维 就我一个人,后面还有很事情要做。 现在主要的是网站的传输加密 ,需要我这边来处理目前还不有头绪,有知道同学请留言。
编辑回复