1024programmer Nginx Installation and use of nginx in linux system

Installation and use of nginx in linux system

Preparation:
# yum install gcc gcc-cpp gcc-c++

Install pcre
(Let nginx support rewrite)
# tar zxvf pcre-8.01.tar.gz
# cd pcre-8.01/
# ./configure
# make && make install

Installation and activation
# tar zxvf nginx-1.0.4.tar.gz
# cd nginx-1.0.4
# ./configure –prefix=/usr/local/nginx
–with-http_gzip_static_module –with-http_flv_module
–http-proxy-temp-path=/var/tmp/nginx/proxy/
# make && make install
start
# /usr/local/nginx/sbin/nginx -c
/usr/local/nginx/conf/nginx.conf
stop
# kill – QUIT Nginx main process number
reboot
# kill -HUP Nginx main process ID

Common configuration
If installed as above, the nginx configuration file is located at /local/usr/nginx/conf/nginx.conf.
The configuration file structure of nginx.conf mainly consists of the following parts:
……
envents {
 …
}

http {
 …
server{

 …

}

server{

 …

}
 …
}

Note: In the following configurations, the position of the modified content will be named with the name before the above curly braces. If the configuration content is modified in the server, it will be described as “what to look for in the server block, why to modify or what to add, etc.”.
1. Set the listening port, domain name and root directory
In the server block of the configuration file, make corresponding settings.

listen
80;
server_name www.domain.com;

root /var/www/domain.com;
index index.php index.html index.htm

Modify listen and server_name to the content you need to set, and add two settings of root and index.
2. Compression settings
Find “# gzip in the configuration file http block
on;”, remove the # sign before gzip, and add the following content in the next line.
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain
application/x-Javascript text/css application/xml;
gzip_vary on;

gzip_types indicates the file header that enables the compression function, and the above settings are text, js, css, and xml for file compression.
3. Set the browser cache time (expires)
In the server block of the configuration file, add the following content.
location ~
.*\.(gif|jpg|jpeg|png|bmp|wsf)$ {
expires
30d;
}
location ~ .*\.(js|css)$ {
expires
1h;
}

Among the above settings, the first one means that all gif, jpg, jpeg, png, bmp, and wsf files will be cached invalid after 30 days after access; the second one means that all js and css files will be cached invalid after 1 hour after access .
4. Set up reverse proxy

For example, to transfer all php requests under the domain name to apache for processing, we can set the following content in the corresponding server block of the configuration file.
location ~ \.php$ {

proxy_pass http://127.0.0.1:8080;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;
}

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/installation-and-use-of-nginx-in-linux-system/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索