In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what Nginx commands developers and administrators should master. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
17. Find Nginx.
PIDPID or process ID is the only number used to distinguish between processes on Linux and Unix-like systems. We can use the appropriate PID to send various signals to the Nginx server. You can find this PID using one of the following commands.
[linuxidc@localhost ~ / www.linuxidc.com] $ps aux | grep [n] ginx root 3834 0.0 117740 2188? Ss 05:01 0:00 nginx: master process / usr/sbin/nginx nginx 3835 0.0 0.2 148772 7704? S 05:01 0:00 nginx: worker process [linuxidc@localhost ~ / www.linuxidc.com] $pgrep nginx 3834 3835 [linuxidc@localhost ~ / www.linuxidc.com] $cat / run/nginx.pid 3834
Therefore, we can use the pgrep or vanilla grep command with ps.
18. Find log files
The log file contains a lot of information that is valuable to system administrators and developers. Nginx has two default log files, which consist of access.log and error.log documents. These are located at / var/log and can be viewed using the following command.
[root@localhost / home/linuxidc/www.linuxidc.com] $ls / var/log/nginx/*.log / var/log/nginx/access.log / var/log/nginx/error.log
You should now see the log files mentioned above. As the name implies, access.log contains information about visitors to your site, while error.log contains warnings / details about misconfiguration. However, you need to enable these two logs from the Nginx configuration file before you can use them.
19. Set up a virtual host
Virtual hosts allow server administrators to run multiple Web sites on a single server computer. This is often useful because you can share your calculation process to run multiple sites at the same time. However, the term virtual host is usually associated with an Apache server. In the Nginx world, they are called "server blocks".
[linuxidc@localhost ~ / www.linuxidc.com] $sudo ln-s / etc/nginx/sites-available/linuxidc.com / etc/nginx/sites-enabled/linuxidc.com
You can easily enable virtual hosting on the Nginx server using this simple symbolic link. If you want to disable virtual hosts, simply remove the symbolic link.
20. View compiled Nginx modules
As you saw in the previous Nginx command, some basic modules are also installed when the daemon is installed. We can easily view these Nginx modules using the following command.
[linuxidc@localhost ~ / www.linuxidc.com] $sudo 2 > & 1 nginx-V | tr -'\ n'| grep _ module
This command takes advantage of several Linux command-line tools and filters out irrelevant information to display only the module. Because Nginx has many modules, this command is useful for checking which modules have been compiled for the server.
21. Enable / disable Nginx service
Enabling the Nginx service causes the server to start automatically during startup. This is critical for dedicated servers, because otherwise, user requests may be interrupted. We can easily make Nginx start automatically using the following command.
[linuxidc@localhost ~ / www.linuxidc.com] $sudo service nginx enable # System V Init [linuxidc@localhost ~ / www.linuxidc.com] $sudo systemctl enable nginx # based on systemd system
These simple but effective commands based on systemd systems will ensure that server downtime is minimized. You can also disable automatic startup as needed. Just use one of the following commands.
[linuxidc@localhost ~ / www.linuxidc.com] $sudo update-rc.d-f nginx disable [linuxidc@localhost ~ / www.linuxidc.com] $sudo systemctl disable nginx
22. Upgrade Nginx immediately
Nginx allows administrators to instantly upgrade binaries and / or configuration files. This means that your client requests will not be interrupted by server upgrades. To do this, first, we need to find the PID of the main Nginx process. We can do this using the simple commands that have been demonstrated.
[linuxidc@localhost ~ / www.linuxidc.com] $cat / run/nginx.pid
The new Nginx binaries should be ready. Generate a new set of Nginx master / worker processes that use the new binaries with the following command.
[linuxidc@localhost ~ / www.linuxidc.com] $sudo kill-s USR2 `cat / run/ nginx.pid`
Now, use the following command to kill the worker process used by the first main process.
[linuxidc@localhost ~ / www.linuxidc.com] $sudo kill-s WINCH `cat / run/ nginx.pid.oldbin`
Track it by killing the old main process.
[linuxidc@localhost ~ / www.linuxidc.com] $sudo kill-s QUIT `cat / run/ nginx.pid.oldbin`
23. Set up Nginx in Chroot Jail
The Chroot Jail of the Nginx server will provide additional security protection in the event of an intrusion. Administrators often use this technique to ensure that their servers are isolated and secure in a small portion of the Linux file system. Use the following command to set up the Nginx server in Chroot Jail.
# D=/nginx # mkdir-p $D # mkdir-p $D/etc # mkdir-p $D/dev # mkdir-p $D/var # mkdir-p $D/usr # mkdir-p $D/usr/local/nginx # mkdir-p $D/tmp # chmod 1777$ D/tmp # mkdir-p $D/var/tmp # chmod 1777$ D/var/tmp # mkdir-p $D/lib64 # ls-l / dev/ {null,random,urandom} # / bin/cp-farv / usr/local/nginx/* $D/usr/local/nginx
You need to run them as a superuser. Now, use the following command to find the shared library.
# ldd / usr/local/nginx/sbin/nginx
Copy all the libraries one by one as shown below.
# cp / lib64/libpcre.so.0$ D/lib64
You also need to copy / etc and other directories.
# cp-fv / etc/ {group,prelink.cache,services,adjtime,shells,gshadow,shadow,hosts.deny,localtime,nsswitch.conf,nscd.conf,prelink.conf,protocols,hosts,passwd,ld.so.cache,ld.so.conf,resolv.conf,host.conf} $D/etc # cp-avr / etc/ {ld.so.conf.d,prelink.conf.d} $D/etc
Your Chroot Jail is now ready to accept Nginx. Just kill the old service and start the new service with the next command.
# / usr/sbin/chroot / nginx/ usr/local/nginx/sbin/nginx-t
24. Running Nginx in Docker
Docker containers have become very popular because of their flexibility and powerful performance. You can easily create and run Nginx Web servers from the Docker container. The next command will extract the official Nginx image and create a server instance with the default configuration.
[root@localhost / home/linuxidc/www.linuxidc.com] $docker run-name nginx-server-P-d nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx 123275d6e508: Pull complete 6cd6a943ce27: Pull complete a50b5ac4a7fb: Pull complete Digest: sha256:d81f010955749350ef31a119fb94b180fde8b2f157da351ff5667ae037968b28 Status: Downloaded newer image for nginx:latest b235541342e380c9e57aad547d52292da89e2c26d9cf6a1548d568a4073136ed
You can use the following simple command to maintain persistent storage.
Sudo docker run-- name nginx-server-v / var/www:/usr/share/nginx/html:ro\-v / var/nginx/conf:/etc/nginx:ro-P-d nginx
25. Running Nginx within LXD
LXD is known as the next generation Linux container and provides a series of amazing features. You can also use Nginx through the LXD container. Take a look at the following Nginx command for LXD.
$sudo lxc launch ubuntu:18.04 nginx-server $sudo lxc exec nginx-server-- sudo-- user ubuntu-- login $sudo apt update $sudo apt install-y nginx $sudo systemctl reload nginx
First, we created a container called nginx-server, and then started a shell in that container. Then we updated the package list and installed the Nginx Web server in the container. The last command simply reloads the server.
This is the end of this article on "what Nginx commands developers and administrators should master". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.