* pre-steps:
* basic prepare of server,
* create user 'dev'
which will be the owner of "/var/www/html",
*
* install nginx,
*
*
* create user 'front'
sudo useradd -d /home/front -s /bin/bash front
sudo passwd front
# create home folder, if not exists yet,
sudo mkdir /home/front
# set owner of new home folder,
sudo chown -R front:front /home/front
# switch to user,
su - front
# copy .bashrc, if not exists yet,
cp /etc/skel/.bashrc ~front/
cp /etc/skel/.profile ~front/
# enable color,
vi ~front/.bashrc
# uncomment the line start with "force_color_prompt",
# exit user
exit
*
* add to group 'dev',
sudo usermod -a -G dev front
* change owner of web dir,
sudo chown -R dev:dev /var/www
* change permission of web dir,
chmod 775 $(find /var/www/html -type d)
chmod 664 $(find /var/www/html -type f)
*
* re-login as 'front'
to make group take effect,
*
* test
*
* ok
*
8 回答
您可以使用apache用户和FTP用户创建一个新组作为成员,然后在上传文件夹775上获得权限 . 这应该使apache和FTP用户能够写入文件夹中的文件但保留其他人从修改它们 .
还要记住
CHOWN
或chgrp
您的网站文件夹 . 试试myusername# chown -R myusername:_www uploads
如果你真的想这样做,我会选择Ryan的答案 .
通常在* nix环境中,您总是希望尽可能少地放弃权限 .
10次中有9次,755是理想的权限 - 因为唯一能够修改文件的用户将是网络服务器 . 如果您真的需要更改此设置,请将您的ftp用户更改为775 .
由于're new to php by your own admission, here'是一个有用的链接,可以提高上传服务的安全性:move_uploaded_file
我将补充一点,如果您正在使用SELinux,您需要确保类型上下文是tmp_t您可以通过使用chcon实用程序来完成此操作
重要的是
apache
用户和组应该具有最小的read
访问权限,在某些情况下execute
访问权限 . 其余的你可以给0
访问权限 .这是最安全的设置 .
基于
@Ryan Ahearn
的答案,以下是我在Ubuntu
16.04上创建的用户front
,该用户只拥有nginx的web目录/var/www/html
的权限 .Steps:
或至少766 .
读= 4
write = 2
execute = 1
7 =读写执行
6 =读写
第一个号码:所有者
第二个数字:组
第三个号码:其他用户
我支持创建一个有权上传的ftp组的想法 . 但是,我认为没有必要给予775许可 . 7代表读,写,执行 . 通常,您希望允许某些组进行读写操作,但根据具体情况,可能不需要执行 .