Under the Uubuntu environment, the http service is set up in the super detailed Nginx, and specific folders are accessed and downloaded

Posted by Jak-S on Thu, 17 Feb 2022 12:27:57 +0100

catalogue

Nginx installation

1, Install compilation tools and library files

2, First install PCRE

Install Nginx

Nginx configuration

Start NginxNginx

Access sites and specific folders

Nginx other commands

Nginx installation

System platform: Ubuntu 18 04 (operation of other system platforms is similar)

Important: in the following installation tutorials, the premise is that some basic dependency packages in your system platform are relatively complete; If it is incomplete, it will appear

. / configure, make, make install and other errors;

eg: execution/ After configure, prompt: Can't find Tcl configuration definitions

Or after executing make, the prompt: Make: will also appear. Make: * * * does not specify the target and cannot find the makefile. Stop (Reference: https://bbs.csdn.net/topics/350227678)

Before proceeding with the following steps, update the software package

sudo apt-get install build-essential

1, Install compilation tools and library files

apt-get install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

2, First install PCRE

PCRE is used to enable Nginx to support Rewrite function.

1. Download the PCRE installation package at: https://sourceforge.net/projects/pcre/files/pcre/8.44/pcre-8.44.tar.gz/download (8.44 is currently the latest)

[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget https://sourceforge.net/projects/pcre/files/pcre/8.44/pcre-8.44.tar.gz/download

2. Unzip the installation package:

[root@bogon src]# tar zxvf pcre-8.44.tar.gz

3. Enter the installation package directory

[root@bogon src]# cd pcre-8.44

4. Compile and install

[root@bogon pcre-8.44]# ./configure
[root@bogon pcre-8.44]# make && make install

Friendly tips: there may be errors during installation. First face Baidu; Because everyone's system environment is different, some dependent packages do not; Not for Baidu, leave a message again;

5. View pcre version

[root@bogon pcre-8.44]# pcre-config --version

Install Nginx

1. Download Nginx at: https://nginx.org/en/download.html

Execute the following two commands to execute nginx-1.20.0 tar. GZ installation package download:

root@bianbian-Lenovo-XiaoXin-700-15ISK:/home/bianbian# cd /usr/local/src/
root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/src# wget http://nginx.org/download/nginx-1.20.0.tar.gz

Downloading

2. Unzip the installation package

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/src# tar zxvf nginx-1.20.0.tar.gz

3. Enter the installation package directory

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/src# cd nginx-1.20.0

4. Compile and install

ll view the next file

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/src/nginx-1.20.0# ll

Compile and install

[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.44
[root@bogon nginx-1.6.2]# make
[root@bogon nginx-1.6.2]# make install

5. View nginx version

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/src/nginx-1.20.0# /usr/local/webserver/nginx/sbin/nginx -v

 

At this point, nginx installation is complete

Nginx configuration

Create users for Nginx operation www:

[root@bogon conf]# /usr/sbin/groupadd www 
[root@bogon conf]# /usr/sbin/useradd -g www www

Friendly tip: when you check the nginx address, you will find that your nginx is in / usr/local/nginx

Nginx here is just a compressed file. When you configure nginx Be sure not to configure the INX path in this case, otherwise it will be invalid

Configure nginx Conf, set / usr / local / webserver / nginx / conf / nginx Replace conf with the following

1. First enter the correct nginx address

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/src/nginx-1.20.0# cd /usr/local/webserver/nginx/conf/

2. Use ll to view the files in this directory

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/webserver/nginx/conf# ll

Enter ngx.in3 conf

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/webserver/nginx/conf# vim nginx.conf

Such a page appears, which is configured by myself. What you appear is different from me

Replace the contents with the following

user www www;
worker_processes 1; #The setting value is consistent with the number of CPU cores
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #Log location and log level
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{
  include mime.types;
  default_type application/octet-stream;
  log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';

#charset gb2312;

  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;

  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on;
 #limit_zone crawler $binary_remote_addr 10m;
 #The following is the configuration of server virtual host
      server {

        listen   6451;
        server_name  asdzyy.com;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /bin/ {
               root   /usr/;
               autoindex on;  #Enable directory browsing
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   html;
        }
    }
}

After replacement, save and exit nginx conf

4. Check the configuration file nginx Correctness command of conf

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/webserver/nginx/conf# /usr/local/webserver/nginx/sbin/nginx -t

The result is correct. If you are not correct, you will be prompted that there is an error in that line. Modify according to the prompt. The error is willing to be because some brackets are missing or the format is misaligned when you replace the code

Start NginxNginx

The startup command is as follows:

root@bianbian-Lenovo-XiaoXin-700-15ISK:/usr/local/webserver/nginx/conf# /usr/local/webserver/nginx/sbin/nginx

You can view the operation through the following commands:

ps -ef|grep nginx 

Access sites and specific folders

Access our configured site ip from the browser

Access specific files:

This is the folder I set to access under / usr/bin /. If you follow the steps, you will also see this file;

If you want to modify the accessed folder, refer to the following link:

Reference:( https://blog.csdn.net/a760352276/article/details/106774599?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.vipsorttest&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.vipsorttest)

Nginx other commands

The following contains several commands commonly used by Nginx

/usr/local/webserver/nginx/sbin/nginx -s reload            # Reload configuration file
/usr/local/webserver/nginx/sbin/nginx -s reopen            # Restart Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop              # Stop Nginx

reference resources:

https://www.runoob.com/linux/nginx-install-setup.html

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Topics: Linux Nginx