Look no further, Linux installs Nginx here!

Nginx is a very lightweight HTTP server written by Russians. Nginx, pronounced "engine X", is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. At present, many domestic websites use Nginx as their web server, such as domestic well-known Sina, NetEase, Tencent, ByteDance, Douban, etc. According to netcraft statistics, Nginx will rank first in the web server market share in 2023 , and similar products include Apache, lighttpd, and Microsoft's IIS.

Nginx has high stability. For other HTTP servers, when encountering a peak value of access, or someone maliciously initiates a slow connection, it is also likely to cause the server's physical memory to run out of frequent exchanges, lose response, and have to restart the server. For example, once the current Apache reaches more than 200 processes, the web response speed is obviously very slow. Nginx adopts staged resource allocation technology, which makes its CPU and memory usage very low. Nginx officially stated that it maintains 10,000 inactive connections, and it only occupies 2.5M memory, so attacks like DOS are basically useless to nginx. In terms of stability, nginx is better than lighthttpd.

Install

Compile and install

ruby
复制代码
# 先安装依赖软件
[thinktik@thinkdev:envs]$ dnf install pcre pcre-devel zlib zlib-devel openssl openssl-devel
# 解压
[thinktik@thinkdev:envs]$ tar -zxvf nginx-1.24.0.tar.gz
# 建立安装目录
[thinktik@thinkdev:envs]$ mkdir nginx
# 进入文件夹
[thinktik@thinkdev:envs]$ ls
 nginx  nginx-1.24.0  nginx-1.24.0.tar.gz
[thinktik@thinkdev:envs]$ cd nginx-1.24.0
# 设置安装文件路径为/home/thinktik/envs/nginx并指定安装SSL模块
[thinktik@thinkdev:nginx-1.24.0]$ ./configure --prefix=/home/thinktik/envs/nginx --with-http_ssl_module
# 编译
[thinktik@thinkdev:nginx-1.24.0]$ make
# 安装
[thinktik@thinkdev:nginx-1.24.0]$ make install

start and verify

We enter the installation directory /home/thinktik/install/nginx and see that nginx already has installed files

ruby
复制代码
[thinktik@thinkdev:envs]$ cd nginx
[thinktik@thinkdev:nginx]$ ls
conf  html  logs  sbin
[thinktik@thinkcent nginx]$ cd sbin/
[thinktik@thinkdev:sbin]$ ls
nginx
[thinktik@thinkdev:sbin]$ su
Password: 
[root@thinkdev sbin]# ./nginx
# 验证nginx运行状态以及监听端口
[root@thinkdev sbin]# netstat -lnt |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
[root@thinkdev sbin]# ps -ef |grep nginx
root       10339       1  0 20:23 ?        00:00:00 nginx: master process ./nginx
nobody     10340   10339  0 20:23 ?        00:00:00 nginx: worker process
root       10348   10322  0 20:24 pts/0    00:00:00 grep --color=auto nginx
# 防火墙放行80/443端口运行外部主机访问
[root@thinkdev sbin]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@thinkdev sbin]# firewall-cmd --zone=public --add-port=443/tcp --permanent
success
[root@thinkdev sbin]# firewall-cmd --reload
success

At this time, we can verify by entering the ip address of our host on the browser, not much to say.

Set up autostart

Edit the file /usr/lib/systemd/system/nginx.serviceand fill in the following content:

ini
复制代码
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
# 指定自己编译的nginx的可执行路径
ExecStartPre=/home/thinktik/envs/nginx/sbin/nginx -t
ExecStart=/home/thinktik/envs/nginx/sbin/nginx
ExecReload=/home/thinktik/envs/nginx/sbin/nginx -s reload
ExecStop=/home/thinktik/envs/nginx/sbin[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

Update systemd and start the service. If you encounter Failed at step EXEC spawning... Permission denied , it is likely that SELinux prevents the normal operation of the service for security reasons. At this time, close SElinux or set SElinux to release the nginx service and then start the service!

csharp
复制代码
# 更新systemd
[root@thinkdev ~]# systemctl daemon-reload
# 启动nginx服务
[root@thinkdev ~]# systemctl start nginx.service
# 关闭nginx服务
[root@thinkdev ~]# systemctl stop nginx.service
[root@thinkdev ~]# systemctl start nginx.service
# 查看nginx服务状态
[root@thinkdev ~]# systemctl status nginx.service

image

Force HTTPS

ini
复制代码
    server {
         listen  80;
         server_name www.xxx.cc xxx.cc;
         # 80转发到443
         return  301 https://$server_name$request_uri;
    }
     
    server {
        listen 443 ssl;
        server_name www.xxx.cc omoz.cc;
        root html;
        index index.html index.htm;
        ssl_certificate cert/cert-file-name.pem;
        ssl_certificate_key cert/cert-file-name.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
            # 后端服务地址
            proxy_pass http://localhost:4000;
        }
    }

Digression

In this first year of fast-growing technology, programming is like a ticket to a world of infinite possibilities for many people. In the star lineup of programming languages, Python is like the leading superstar. With its concise and easy-to-understand syntax and powerful functions, it stands out and becomes one of the most popular programming languages ​​in the world.


The rapid rise of Python is extremely beneficial to the entire industry , but " 人红是非多" has caused it to add a lot of criticism, but it still cannot stop its hot development momentum.

Will Python remain relevant and intact for the rest of the next decade? Today, we're going to analyze the facts and dispel some misconceptions.

If you are interested in Python and want to get a higher salary by learning Python, then the following set of Python learning materials must be useful to you!

Materials include: Python installation package + activation code, Python web development, Python crawler, Python data analysis, artificial intelligence, machine learning and other learning tutorials. Even beginners with 0 basics can understand and understand. Follow the tutorial and take you to learn Python systematically from zero basics!

1. Learning routes in all directions of Python

The route of all directions in Python is to organize the commonly used technical points of Python to form a summary of knowledge points in various fields. Its usefulness lies in that you can find corresponding learning resources according to the above knowledge points to ensure that you learn more comprehensively.
insert image description here
2. Python learning software

If a worker wants to do a good job, he must first sharpen his tools. The commonly used development software for learning Python is here!
insert image description here
3. Python introductory learning video

There are also many learning videos suitable for getting started with 0 basics. With these videos, you can easily get started with Python~insert image description here

4. Python exercises

After each video lesson, there are corresponding practice questions, you can test the learning results haha!
insert image description here

Five, Python actual combat case

Optical theory is useless. You have to learn to type codes along with it, and then you can apply what you have learned in practice. At this time, you can learn from some practical cases. This information is also included~insert image description here

6. Python interview materials

After we have learned Python, we can go out and find a job with the skills! The following interview questions are all from first-line Internet companies such as Alibaba, Tencent, and Byte, and some Alibaba bosses have given authoritative answers. After reading this set of interview materials, I believe everyone can find a satisfactory job.
insert image description here
insert image description here
7. Information collection

The full set of learning materials for the above-mentioned full version of Python has been uploaded to the CSDN official website. Those who need it can scan the QR code of the CSDN official certification below on WeChat to receive it for free.

Guess you like

Origin blog.csdn.net/Python966/article/details/132364939