Centos7 配置 Nginx 和 FTP

Nginx

安装 Nginx

yum install nginx

启动 Nginx

systemctl start nginx.service

设置开机启动

systemctl enable nginx.service

其他功能

# 查看nginx状态
systemctl status nginx.service         

# 重启nginx
systemctl restart nginx

# 查看是否开机启动
systemctl is-enabled nginx 

# 检测nginx运行情况
nginx -t                 

修改 Nginx 配置文件,设置域名和 root 页面

vi /etc/nginx/nginx.conf

                                                                                                                                                                                                                                                                                   
    server {                                                                                               
        listen       80 default_server;                                                                    
        listen       [::]:80 default_server;                                                               
        server_name  www.site1.com *.site2.com;       # 改为你的网站域名                                                            
        root         /usr/share/nginx/html;           # 改为你的默认首页路径                                                                
                                                                                                           
        # Load configuration files for the default server block.                                           
        include /etc/nginx/default.d/*.conf;                                                               
                                                                                                           
        location / {                                                                                       
        }                                                                                                  
                                                                                                           
        error_page 404 /404.html;                                                                          
            location = /40x.html {                                                                         
        }                                                                                                  
                                                                                                           

退出并保存文件

:wq

在浏览器输入 VPS 的 IP 地址就可以看到 Nginx 欢迎页面了。

FTP

安装 vsftpd

yum -y install vsftpd

启动 FTP 服务

service vsftpd start

# 开机启动
chkconfig vsftpd on

修改vsftpd的配置文件

vi /etc/vsftpd/vsftpd.conf

1.不允许匿名访问

anonymous_enable=NO

2.允许使用本地帐户进行FTP用户登录验证

local_enable=YES

3.使用户不能离开主目录

当chroot_list_enable=YES,chroot_local_user=YES时,在/etc/vsftpd.chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录。

chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

配置文件最后添加这段,不然会报错

allow_writeable_chroot=YES

如果/etc/vsftpd/chroot_list不存在,则需要创建该文件

vi /etc/vsftpd/chroot_list

重启 vsftpd

systemctl restart vsftpd.service

新建FTP用户,设置用户主目录

useradd -d <ftp用户主目录> -g ftp -s /sbin/nologin <ftpname>

修改 FTP 主目录权限

chmod 777 -R /your/ftp/folder

然后就可以登录FTP了。

链接:

Nginx配置实战