赞
踩
Nginx is a high-performance web server. As a developer, you also need to be in constant contact with it. Today we will introduce how to install and use Nginx on Linux mint 19.3. Considering that Linux mint 19.3 is built on Ubuntu 18.04, this article is also applicable to Ubuntu 18.04.
lwk@qwfys:~$ apt list |grep nginx WARNING: apt does not have a stable CLI interface. Use with caution in scripts. kopano-webapp-nginx/bionic 3.4.6+dfsg1-1 all libnginx-mod-http-auth-pam/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-cache-purge/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-dav-ext/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-echo/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-fancyindex/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-geoip/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-headers-more-filter/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-image-filter/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-lua/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-ndk/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-perl/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-subs-filter/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-uploadprogress/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-upstream-fair/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-http-xslt-filter/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-mail/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-nchan/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-rtmp/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 libnginx-mod-stream/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 lua-nginx-cookie/bionic 0.1.0-1 all lua-nginx-dns/bionic 0.20-1 all lua-nginx-kafka/bionic 0.06-1 all lua-nginx-memcached/bionic 0.10-1 all lua-nginx-redis/bionic 0.26-1 all lua-nginx-redis-connector/bionic 0.06-1 all lua-nginx-string/bionic 0.10-1 all lua-nginx-websocket/bionic 0.06-1 all nginx/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 all nginx-common/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 all nginx-core/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 nginx-doc/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 all nginx-extras/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 nginx-full/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 nginx-light/bionic-security,bionic-updates 1.14.0-0ubuntu1.7 amd64 python-certbot-nginx/bionic 0.23.0-1 all python-certbot-nginx-doc/bionic 0.23.0-1 all python3-certbot-nginx/bionic 0.23.0-1 all lwk@qwfys:~$
We see that Nginx is not installed on the current host, but there is already information about Nginx in the local apt cache. Next, we complete the nginx installation based on the apt command.
lwk@qwfys:~$ apt install nginx -y [sudo] password for lwk: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-5.3.0-40 linux-headers-5.3.0-40-generic linux-image-5.3.0-40-generic linux-modules-5.3.0-40-generic linux-modules-extra-5.3.0-40-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common nginx-core Suggested packages: fcgiwrap nginx-doc The following NEW packages will be installed: libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx nginx-common nginx-core 0 upgraded, 8 newly installed, 0 to remove and 3 not upgraded. Need to get 598 kB of archives. After this operation, 2,120 kB of additional disk space will be used. Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 nginx-common all 1.14.0-0ubuntu1.7 [37.4 kB] Get:2 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libnginx-mod-http-geoip amd64 1.14.0-0ubuntu1.7 [11.2 kB] Get:3 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libnginx-mod-http-image-filter amd64 1.14.0-0ubuntu1.7 [14.6 kB] Get:4 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libnginx-mod-http-xslt-filter amd64 1.14.0-0ubuntu1.7 [13.0 kB] Get:5 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libnginx-mod-mail amd64 1.14.0-0ubuntu1.7 [41.8 kB] Get:6 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libnginx-mod-stream amd64 1.14.0-0ubuntu1.7 [63.7 kB] Get:7 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 nginx-core amd64 1.14.0-0ubuntu1.7 [413 kB] Get:8 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 nginx all 1.14.0-0ubuntu1.7 [3,596 B] Fetched 598 kB in 7s (84.2 kB/s) Preconfiguring packages ... Selecting previously unselected package nginx-common. (Reading database ... 424845 files and directories currently installed.) Preparing to unpack .../0-nginx-common_1.14.0-0ubuntu1.7_all.deb ... Unpacking nginx-common (1.14.0-0ubuntu1.7) ... Selecting previously unselected package libnginx-mod-http-geoip. Preparing to unpack .../1-libnginx-mod-http-geoip_1.14.0-0ubuntu1.7_amd64.deb ... Unpacking libnginx-mod-http-geoip (1.14.0-0ubuntu1.7) ... Selecting previously unselected package libnginx-mod-http-image-filter. Preparing to unpack .../2-libnginx-mod-http-image-filter_1.14.0-0ubuntu1.7_amd64.deb ... Unpacking libnginx-mod-http-image-filter (1.14.0-0ubuntu1.7) ... Selecting previously unselected package libnginx-mod-http-xslt-filter. Preparing to unpack .../3-libnginx-mod-http-xslt-filter_1.14.0-0ubuntu1.7_amd64.deb ... Unpacking libnginx-mod-http-xslt-filter (1.14.0-0ubuntu1.7) ... Selecting previously unselected package libnginx-mod-mail. Preparing to unpack .../4-libnginx-mod-mail_1.14.0-0ubuntu1.7_amd64.deb ... Unpacking libnginx-mod-mail (1.14.0-0ubuntu1.7) ... Selecting previously unselected package libnginx-mod-stream. Preparing to unpack .../5-libnginx-mod-stream_1.14.0-0ubuntu1.7_amd64.deb ... Unpacking libnginx-mod-stream (1.14.0-0ubuntu1.7) ... Selecting previously unselected package nginx-core. Preparing to unpack .../6-nginx-core_1.14.0-0ubuntu1.7_amd64.deb ... Unpacking nginx-core (1.14.0-0ubuntu1.7) ... Selecting previously unselected package nginx. Preparing to unpack .../7-nginx_1.14.0-0ubuntu1.7_all.deb ... Unpacking nginx (1.14.0-0ubuntu1.7) ... Setting up nginx-common (1.14.0-0ubuntu1.7) ... Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service. Setting up libnginx-mod-http-image-filter (1.14.0-0ubuntu1.7) ... Setting up libnginx-mod-mail (1.14.0-0ubuntu1.7) ... Setting up libnginx-mod-http-xslt-filter (1.14.0-0ubuntu1.7) ... Setting up libnginx-mod-http-geoip (1.14.0-0ubuntu1.7) ... Setting up libnginx-mod-stream (1.14.0-0ubuntu1.7) ... Setting up nginx-core (1.14.0-0ubuntu1.7) ... Setting up nginx (1.14.0-0ubuntu1.7) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ... Processing triggers for ureadahead (0.100.0-21) ... ureadahead will be reprofiled on next reboot Processing triggers for systemd (237-3ubuntu10.39) ... lwk@qwfys:~$
Now that Nginx has been installed, let’s check if the status of the Nginx service is starting.
lwk@qwfys:~$ systemctl status nginx.service ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2020-03-21 22:15:40 CST; 1min 42s ago Docs: man:nginx(8) Main PID: 5557 (nginx) Tasks: 9 (limit: 4915) CGroup: /system.slice/nginx.service ├─5557 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─5560 nginx: worker process ├─5562 nginx: worker process ├─5564 nginx: worker process ├─5566 nginx: worker process ├─5569 nginx: worker process ├─5570 nginx: worker process ├─5571 nginx: worker process └─5572 nginx: worker process Mar 21 22:15:40 qwfys systemd[1]: Starting A high performance web server and a reverse proxy server... Mar 21 22:15:40 qwfys systemd[1]: Started A high performance web server and a reverse proxy server. lwk@qwfys:~$
Here we see that the Nginx service is already started. Next, let’s analyze the distribution of Nginx directories under Linux mint environment.
lwk@qwfys:/etc/nginx$ tree ../nginx/ ../nginx/ ├── conf.d ├── fastcgi.conf ├── fastcgi_params ├── koi-utf ├── koi-win ├── mime.types ├── modules-available ├── modules-enabled │ ├── 50-mod-http-geoip.conf -> /usr/share/nginx/modules-available/mod-http-geoip.conf │ ├── 50-mod-http-image-filter.conf -> /usr/share/nginx/modules-available/mod-http-image-filter.conf │ ├── 50-mod-http-xslt-filter.conf -> /usr/share/nginx/modules-available/mod-http-xslt-filter.conf │ ├── 50-mod-mail.conf -> /usr/share/nginx/modules-available/mod-mail.conf │ └── 50-mod-stream.conf -> /usr/share/nginx/modules-available/mod-stream.conf ├── nginx.conf ├── proxy_params ├── scgi_params ├── sites-available │ └── default ├── sites-enabled │ └── default -> /etc/nginx/sites-available/default ├── snippets │ ├── fastcgi-php.conf │ └── snakeoil.conf ├── uwsgi_params └── win-utf 6 directories, 19 files lwk@qwfys:/etc/nginx$ lwk@qwfys:/etc/nginx$ ll total 80 drwxr-xr-x 8 root root 4096 Mar 18 13:31 ./ drwxr-xr-x 161 root root 12288 Mar 18 13:31 ../ drwxr-xr-x 2 root root 4096 Jan 11 03:18 conf.d/ -rw-r--r-- 1 root root 1077 Apr 6 2018 fastcgi.conf -rw-r--r-- 1 root root 1007 Apr 6 2018 fastcgi_params -rw-r--r-- 1 root root 2837 Apr 6 2018 koi-utf -rw-r--r-- 1 root root 2223 Apr 6 2018 koi-win -rw-r--r-- 1 root root 3957 Apr 6 2018 mime.types drwxr-xr-x 2 root root 4096 Jan 11 03:18 modules-available/ drwxr-xr-x 2 root root 4096 Mar 18 13:31 modules-enabled/ -rw-r--r-- 1 root root 1482 Apr 6 2018 nginx.conf -rw-r--r-- 1 root root 180 Apr 6 2018 proxy_params -rw-r--r-- 1 root root 636 Apr 6 2018 scgi_params drwxr-xr-x 2 root root 4096 Mar 18 13:31 sites-available/ drwxr-xr-x 2 root root 4096 Mar 18 13:31 sites-enabled/ drwxr-xr-x 2 root root 4096 Mar 18 13:31 snippets/ -rw-r--r-- 1 root root 664 Apr 6 2018 uwsgi_params -rw-r--r-- 1 root root 3071 Apr 6 2018 win-utf lwk@qwfys:/etc/nginx$ ll conf.d/ total 8 drwxr-xr-x 2 root root 4096 Jan 11 03:18 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ lwk@qwfys:/etc/nginx$ ll modules-available/ total 8 drwxr-xr-x 2 root root 4096 Jan 11 03:18 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ lwk@qwfys:/etc/nginx$ ll modules-enabled/ total 16 drwxr-xr-x 2 root root 4096 Mar 18 13:31 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ lrwxrwxrwx 1 root root 54 Mar 18 13:31 50-mod-http-geoip.conf -> /usr/share/nginx/modules-available/mod-http-geoip.conf lrwxrwxrwx 1 root root 61 Mar 18 13:31 50-mod-http-image-filter.conf -> /usr/share/nginx/modules-available/mod-http-image-filter.conf lrwxrwxrwx 1 root root 60 Mar 18 13:31 50-mod-http-xslt-filter.conf -> /usr/share/nginx/modules-available/mod-http-xslt-filter.conf lrwxrwxrwx 1 root root 48 Mar 18 13:31 50-mod-mail.conf -> /usr/share/nginx/modules-available/mod-mail.conf lrwxrwxrwx 1 root root 50 Mar 18 13:31 50-mod-stream.conf -> /usr/share/nginx/modules-available/mod-stream.conf lwk@qwfys:/etc/nginx$ ll sites-available/ total 12 drwxr-xr-x 2 root root 4096 Mar 18 13:31 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ -rw-r--r-- 1 root root 2416 Apr 6 2018 default lwk@qwfys:/etc/nginx$ ll sites-enabled/ total 8 drwxr-xr-x 2 root root 4096 Mar 18 13:31 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ lrwxrwxrwx 1 root root 34 Mar 18 13:31 default -> /etc/nginx/sites-available/default lwk@qwfys:/etc/nginx$ ll snippets/ total 16 drwxr-xr-x 2 root root 4096 Mar 18 13:31 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ -rw-r--r-- 1 root root 422 Apr 6 2018 fastcgi-php.conf -rw-r--r-- 1 root root 217 Apr 6 2018 snakeoil.conf lwk@qwfys:/etc/nginx$ cat nginx.conf user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #} lwk@qwfys:/etc/nginx$ lwk@qwfys:/etc/nginx$ cd sites-enabled/ lwk@qwfys:/etc/nginx/sites-enabled$ ll total 8 drwxr-xr-x 2 root root 4096 Mar 18 13:31 ./ drwxr-xr-x 8 root root 4096 Mar 18 13:31 ../ lrwxrwxrwx 1 root root 34 Mar 18 13:31 default -> /etc/nginx/sites-available/default lwk@qwfys:/etc/nginx/sites-enabled$ cat default ## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # https://www.nginx.com/resources/wiki/start/ # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ # https://wiki.debian.org/Nginx/DirectoryStructure # # In most cases, administrators will remove this file from sites-enabled/ and # leave it as reference inside of sites-available where it will continue to be # updated by the nginx packaging team. # # This file will automatically load configuration files provided by other # applications, such as Drupal or Wordpress. These applications will be made # available underneath a path with that package name, such as /drupal8. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## # Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass PHP scripts to FastCGI server # #location ~ \.php$ { # include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # #server { # listen 80; # listen [::]:80; # # server_name example.com; # # root /var/www/example.com; # index index.html; # # location / { # try_files $uri $uri/ =404; # } #} lwk@qwfys:/etc/nginx/sites-enabled$
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。