分类 nginx 下的文章

centos6.6配置用户家目录为网站根目录

1.配置虚拟机

[webserver@webserver6602 ~]$ sudo vi /etc/nginx/conf.d/webserver.conf 
server {
    listen       80;
    server_name  webserver.com;

    #charset koi8-r;
    access_log  /var/log/nginx/webserver.access.log  main;
    error_log /var/log/nginx/webserver.error.log warn;
    root   /home/webserver/html;
    location / {
        #root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    #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;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$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;
    #}
}

2.打开selinux
参考:http://blog.csdn.net/qidizi/article/details/41291397

setsebool -P httpd_read_user_content 1  #只设置这个就好了
setsebool -P httpd_enable_homedirs 1 

3.设置文件权限

chmod o+x /home/webserver
chmod o+x /home/webserver/html

4.重启nginx就ok了

centos 6.6默认iptable规则

今天在自己电脑上新装了centos6.6虚拟机,然后装了nginx,没有进行任何其他设置,然后就发现只能在centos上面可以访问nginx,看了下iptable的规则

[root@centos6 ~]# iptables-save
# Generated by iptables-save v1.4.7 on Sun Jul 26 15:53:13 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [5819:366868]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A INPUT -j REJECT --reject-with icmp-host-prohibited 
-A FORWARD -j REJECT --reject-with icmp-host-prohibited 
COMMIT
# Completed on Sun Jul 26 15:53:13 2015

看上去好像没有问题啊,默认策略也是接受,看到最后的两句,不明白是什么意思,搜了下原来是

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
# 这两条的意思是在INPUT表和FORWARD表中拒绝所有其他不符合上述任何一条规则的数据包。并且发送一条host prohibited的消息给被拒绝的主机。

记录下,参考http://zhidao.baidu.com/link?url=1bwvdaSb6sKL_FzefyzVFd5GYoZOE4LMNiSG6Oe4WTGQb4ygdzWXVAlitJqLqQcjG1Zwg_xC1_6-Iflwq69il_

centos6.6设置samba和nginx访问用户家目录

之前都是把服务器搭好,在用php输出一个phpinfo就算是搭建成功了,要搭的环境是要实际运行的,所以出现了一些问题,主要是selinux,虽说直接关掉selinux就可以,但是感觉还是开着好一点,于是。。。。
要共享的是test用户家目录家的www文件夹(/home/test/www)
1.环境都搭好之后,开始共享文件,因为是共享家目录,所以不需要改samba配置文件,增加一个samba用户

smbpasswd -a test
#下面需要设置下用户密码

设置selinux

setsebool -P samba_enable_home_dirs on

ok,可以共享了,进入共享目录,操作文件,没有问题,
2.然后设置nginx共享,可以参见另一篇文章http://blog.csdn.net/scchary/article/details/47017475
然后ok了
3.因为我是用的thinkphp,所以php会自己创建文件,这时候就不行了,权限是ok的,是selinux的问题

chcon -t httpd_sys_content_t -R /home/test/www

参考自:http://www.linuxidc.com/Linux/2012-04/58440.htm
ok
4.再就发现samba不能共享了,又是selinux

setsebool -P samba_export_all_ro on

好了
参考网址http://os.51cto.com/art/201204/332440.htm
5.再就发现thinkphp创建的文件所属组和用户都是 apache (我的php-fpm运行身份是apache:apache),我登陆samba的用户是test,不能操作那些生成的文件,于是想起了SGID

chmod g+x -R /home/test/www

ok