Linux environment nginx to build a simple picture server

  • 2020-05-09 19:51:57
  • OfStack

Nginx and vsftpd are mainly used.
The installation can be downloaded directly from the nginx website, or...


yum install nginx 


If you don't have an yum source, you need to add it yourself and then install.


yum install wget
wget http://www.atomicorp.com/installers/atomic 
sh ./atomic 
yum check update 

If you download it from the official website, do the following:


[root@admin local]# cd /usr/local
[root@admin local]# tar -zxv -f nginx-1.6.2.tar.gz
[root@admin local]# rm -rf nginx-1.6.2.tar.gz
[root@admin local]# mv nginx-1.6.2 nginx
[root@admin local]# cd /usr/local/nginx
[root@admin nginx]# ./configure --prefix=/usr/local/nginx
[root@admin nginx]# make
[root@admin nginx]# make install     

Install vsftpd:


yum install vsftpd 

The nginx configuration is not too complicated, only a virtual directory is created and directory browsing is enabled.
When I want to access http://localhost/apps, the actual access path is /home/appmanager/
First I need to create an apps folder under nginx/html, even though I'm not actually accessing this path.


mkdir /usr/local/nginx/html/apps

Then modify nginx/conf/nginx conf in default server add 1 location and specify the actual path:


    location /apps/ {
        root /home/appmanager/;
        #alias ;
        autoindex on;
        #autoindex_exact_size off;
        #autoindex_localtime on;
    } 

autoindex on is for browsing.
root maps apps to /home/appmanager/apps/
Of course, alias does what I want, but it's a little different.

You then need to create the user, which is appmanager in the configuration file above.


useradd -d /home/appmanager -M appmanager

Then specify the directory and add permissions


chown appmanager /home/appmanager
chmod 777 -R /home/appmanager

For some reason, the first time I created the user's directory, it never took effect, although repeated usermod-d also had no effect...

However, it is now accessible via Jsch api.


public static void main(String[] args) throws JSchException {
    Session session = null;
    ChannelSftp channelSftp = null;
    try {
        JSch.setLogger(new JSCHLogger());
        JSch jsch = new JSch();
        session = jsch.getSession("appmanager", "101.x.x.x", "22");
        session.setPassword("password");         Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();         channelSftp = (ChannelSftp) session.openChannel("sftp");
        channelSftp.connect();     } catch (JSchException | SftpException | IOException e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (channelSftp != null) {
            channelSftp.disconnect();
        }
        if (session != null)
            session.disconnect();
    }
}


Related articles: