Nginx installed in centos7

One: Install
1. Go to the official website to download the latest nginx package

2. Upload nginx to linux system
3. Install dependent environment
and run ok without brain

(1)安装gcc环境
  yum install gcc-c++

(2)安装PCRE库,用于解析正则表达式
 yum install -y pcre pcre-devel

(3)zlib压缩和解压缩依赖,
 yum install -y zlib zlib-devel

(4)SSL 安全的加密的套接字协议层,用于HTTP安全传输,也就是https
 yum install -y openssl openssl-devel

(5)解压,需要注意,解压后得到的是源码,源码需要编译后才能安装我解压到root下
tar -zxvf nginx-1.16.1.tar.gz

(6)编译之前,先创建nginx临时目录,如果不创建,在启动nginx的过程中会报错
mkdir /var/temp/nginx -p

(7)在nginx目录,输入如下命令进行配置,目的是为了创建makefile文件
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

Explanation of command –prefix
specifies nginx installation directory
–pid-path points to nginx's pid
–lock-path locks the installation file to prevent malicious tampering or misoperation
–error-log error log
–http-log-path http log
–with-http_gzip_static_module enabled gzip module, online real-time compressed output data stream –
http-client-body-temp-path set the temporary directory requested by the client –
http-proxy-temp-path set the http proxy temporary directory –
http-fastcgi-temp-path set Set fastcgi temporary directory-
http-uwsgi-temp-path set uwsgi temporary directory-
http-scgi-temp-path set scgi temporary directory

7.make编译
make

8. Installation

#老鸟告诉你这样编译的话会快一点
make -j 4 install

9. Enter the sbin directory to start nginx

./nginx

Stop: ./nginx -s stop
Reload: ./nginx -s reload
Open the browser, visit the intranet ip where the virtual machine is located to open the nginx default page, the following shows the installation is successful:
Note:
1. Cloud server installation The default is to open port 80.
If you need to close the firewall when installing in a virtual machine

Second use
Let's enter the conf to view the core file of ngxin.conf and
enter this directory

[root@huaxinfeng51 conf]# pwd
/usr/local/nginx/conf

vim command to modify the configuration file

[root@huaxinfeng51 conf]# vim nginx.conf

1. The user who sets up the worker process refers to the user in Linux, which will involve some permissions for the nginx operation directory or file. The default is nobody. This is what identity you use to start nginx. If I start with root, you can also create nginx user gives nginx user permissions

user root;

2. The number of workers in the worker process is set. Generally speaking, there are several CPUs, so you can set a few, or set it to N-1 or auto, but according to experience, you can write a few CPUs.
worker_processes 1;

3.nginx log level debug | info | notice | warn | error | crit | alert | emerg, the error level increases from left to right

4. Set the nginx process pid
pid /usr/local/nginx/logs/nginx.pid;

#### When you restart nginx, you will probably get an error and you ca n’t find the pid. In this case, you have to come here. Go to
the nginx installation directory / sbin / and execute
nginx or nginx -c nginx.conf
nginx -c in a specific location … / conf / nginx.conf
and restart

5. Set the working mode

events {
    # 默认使用epoll
    use epoll;
    # 每个worker允许连接的客户端最大连接数
    worker_connections  10240;
}

6.http is the instruction block, some instruction configuration for http network transmission

http {
}

7.include Introduce external configuration to improve readability, avoid a single configuration file is too large, you can look at this file in the conf file

include       mime.types;

8. Set the log format, main is a custom format name, so access_log can use this variable directly

The logs below / var / log / nginx are the green definition above

Parameter name Parameter meaning
$ remote_addr Client ip
$ remote_user Remote client user name, generally: '-'
$ time_local Time and time zone
$ request Request URL and method
$ status Response status code
$ body_bytes_send Response client content bytes
$ http_referer records the link from which the user jumped over to
$ http_user_agent The proxy used by the user, generally comes to the browser
$ http_x_forwarded_for through the proxy server to record the client's IP

9. Sendfile uses efficient file transfer to improve transfer performance. Tcp_nopush can only be used after it is enabled, which means that it is sent only after the data table has accumulated a certain size, which improves efficiency

sendfile        on;
tcp_nopush      on;

10.keepalive_timeout sets the timeout time for client and server requests to ensure that the client will not repeatedly establish a new connection when making multiple requests, saving resource consumption.

#keepalive_timeout  0;
keepalive_timeout  65;

11. gzip enables compression, html / js / css compression will be faster transmission
gzip on;
#open gzip gzip_min_length 1; #less than 1K does not compress
gzip_comp_level 3; #Compression is basically 3 The default is 1-9, but not the bigger the better , The greater the impact on performance, CPU to calculate this compression
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/bmp application/x-bmp image/x-ms-bmp application/vnd.ms-fontobject font/ttf font/opentype font/x-woff;#Compression type

12. The server can set up multiple virtual host
listen in the http command block listening port
server_name localhost, ip, domain name
location request routing mapping, matching intercept
root request location
index home page settings

server {
            listen       88;
            server_name  localhost;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    }
Published 7 original articles · Like 89 · Visits 30,000+

Guess you like

Origin blog.csdn.net/BryantJamesHua/article/details/105519649