Offline compilation and installation of nginx

catoop 2020-11-13 10:21:09
offline compilation installation nginx


download

Official website download nginx Installation package , Download the latest stable (Stable version).
Or visit Site download rpm edition .
This article takes CentOS7 Use rpm Version installation, for example .

install

install nginx There are three ways to use software , about yum and rpm Both installation methods require root user , Because the default write file directory, ordinary users do not have permission . These two ways are also the simplest way , among yum Need your machine to be connected to the Internet ,rpm It doesn't need to be networked , But you need to download the corresponding system rpm file . There are a lot of information about these two ways, and they are very simple , This article does not elaborate , If necessary, please check the information yourself .

Be careful : If you use root The user installs and starts nginx, Please put nginx Change the first line of the configuration file to user nobody It means let nginx With nobody User run ,nobody yes Linux A default user who cannot log in , This can avoid certain security problems .

This paper focuses on the abnormal environment ( Not root Users and servers that can't connect to the Internet ) The installation method of .

Preparation of compiling environment

gcc Compile environment

  • In a network enabled , And the target server operating system version of the same server to compile the file package ( Of course, if you're directly on a machine that can't be connected to the Internet, it's OK , Just offline installation gcc It's going to be a lot of trouble, a waste of time , So it's easier to find a virtual machine that can be networked ).
  • If your target server is networked , Please follow the steps below .
  • If your target server comes with gcc Compile environment ( command gcc --version Determine if the system has been installed ), Please follow the steps below .

Related packages

Compilation and installation

stay gcc Compile on the server

First determine your target server's Not root user name , The non of this article root The user name is shanhy For example , The specific name is optional .
1、 Create user and set password
Use root Users create users and set passwords , If you've been assigned a user , Then skip this step

useradd shanhy
passwd shanhy

2、 install gcc Compile environment
Use root User installation gcc

yum install -y gcc-c++

3、 Switch to non root The user compiles and performs subsequent operations
Switching users

su - nginx

Decompress the package

tar -xzvf nginx-1.18.0.tar.gz
tar -xzvf openssl-1.0.2s.tar.gz
tar -xzvf pcre-8.44.tar.gz
tar -xzvf zlib-1.2.11.tar.gz

To configure

cd nginx-1.18.0
./configure \
--prefix=/home/shanhy/nginx \
--with-pcre=../pcre-8.44 \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.0.2s \
--user=shanhy \
--group=shanhy \
--with-file-aio \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module

among --prefix Set you nginx The directory to which you will eventually need to install , This directory must be the same as the directory you plan to place on the target server you want to copy to , Because after compiling, this configuration is not easy to modify by default .--user and --group Use your faults root User name and the name of the user group in which it is located , Here's how to view the user group that the user belongs to ( Example ):
[shanhy@cib-server1 sbin]$ cat /etc/passwd | grep shanhy
shanhy:x:1002:1003::/home/shanhy:/bin/bash
[shanhy@cib-server1 sbin]$ cat /etc/group | grep 1003
shanhy:x:1003:
For more parameters, please refer to the relevant information .

compile

make && make install

install

make install

After installation --prefix The specified directory will appear, including but not limited to conf|html|sbin|logs A few catalogues .

Use root User authorization

Not root User run nginx Can't monitor 1024 The following port numbers , Because of our nginx Need to use 80 and 443 port , So we need to use root User authorization . Of course if you nginx Using the big port, you can skip this step .

su - root
cd /home/shanhy/nginx/sbin
chown root:root nginx
chmod 755 nginx
chmod u+s nginx

Start the service

Use non root user , Enter the directory and start the service

su - shanhy
cd /home/shanhy/nginx
./sbin/nginx

Open browser access http://{ The server IP} Normal should be able to see nginx Default page for .

Common administrative commands :
View version :nginx –V
Out of Service :nginx -s stop Or through kill nginx Process number
Test configuration :nginx -t
Refresh configuration :nginx -s reload

The package file is sent to the target server for deployment

  • Package the compiled package , Send it to the target server on the pure intranet and unzip it .
  • Use... On the target server root The user is nginx Document Authorization .
  • Start the service .

thus , End of service installation .


To configure

nginx The default master profile for is conf/nginx.conf, We usually create a conf.d The folder is used to distinguish the main configuration file from the sub configuration file ,conf.d Multiple sub configuration files are stored in :

Replace the default profile with the following profile :

#user nobody;
worker_processes 1;
error_log logs/error.log warn;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include ./mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include ./conf.d/*.conf;
}

Be careful : If your nginx It uses root User installed and started , The first line of the configuration file user nobody Please remove the front # notes , This has been explained above .

And then create the directory conf/conf.d, Will the following documents default.conf Into it

server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

If there is a change in the configuration file, modify it , Use after modification sbin/nginx -t Test the grammar and then sbin/nginx -s reload Refresh the configuration .


(END)

版权声明
本文为[catoop]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple