nginx如何编译安装?

2、nginx 编译安装与配置使用(重点)

1、安装相关依赖包

安装gcc g++ pcre软件包gcc gcc-c++ pcre pcre-devel gd-devel(使nginx支持http rewrite模块)

安装openssl openssl-devel(使nginx支持ssl)

安装zlib zlib zlib-devel

yum -y install gcc gcc-c++ pcre pcre-devel gd-devel openssl openssl-devel  zlib zlib-devel
2、创建用户nginx
useradd nginx
3、安装nginx
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar xzf nginx-1.16.0.tar.gz
cd /nginx-1.16.0/
预编译
./configure \
--prefix=/usr/local/nginx \
--group=nginx \
--user=nginx \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
编译安装
make && make install
4、添加环境变量
cat >/etc/profile.d/nginx.sh<<EOF
export PATH=\${PATH}:/usr/local/nginx/sbin
EOF
source /etc/profile
5、配置文件
yum安装配置文件位置:/etc/nginx/nginx.conf
源码安装配置文件位置:/usr/local/nginx/conf/nginx.conf
```
#1.nginx.conf的组成:nginx.conf一共由三部分组成,分别为:全局块、events块、http块。在http块中又包含http全局块、多个server块。每个server块中又包含server全局块以及多个location块。在统一配置块中嵌套的配置快,各个之间不存在次序关系。
备份原配置文件产生配置文件
mv /usr/local/nginx/conf/nginx.conf{,.bak}
整理配置文件如下所示:
cat >/usr/local/nginx/conf/nginx.conf<<EOF
user  nobody;
worker_processes  1;
error_log  logs/error.log;
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;
    server {
        listen       80;
        server_name  localhost;
        access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
  }
}
EOF
5、开机自启服务
cat >/usr/lib/systemd/system/nginx.service<<EOF
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
LimitNOFILE=51200
LimitNPROC=51200
LimitCORE=51200

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx
6、检测nginx配置文件
/usr/local/nginx/sbin/nginx -t
7、启动nginx服务
使用系统服务启动
systemctl start nginx
直接启动
/usr/local/nginx/sbin/nginx
8、 nginx 命令功能
nginx -c /path/nginx.conf  	     # 以特定目录下的配置文件启动nginx:
nginx -s reload            	 	 # 修改配置后重新加载生效
nginx -s stop  				 	 # 快速停止nginx
nginx -s quit  				 	 # 正常停止nginx
nginx -t    					 # 测试当前配置文件是否正确
nginx -t -c /path/to/nginx.conf  # 测试特定的nginx配置文件是否正确
#注意:
nginx -s reload 命令加载修改后的配置文件
9、ngin

相关推荐

  1. nginx如何编译安装?

    2024-06-07 06:24:04       29 阅读
  2. Ubuntu 编译安装 nginx

    2024-06-07 06:24:04       44 阅读
  3. Centos8 使用编译安装nginx

    2024-06-07 06:24:04       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-07 06:24:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-07 06:24:04       101 阅读
  3. 在Django里面运行非项目文件

    2024-06-07 06:24:04       82 阅读
  4. Python语言-面向对象

    2024-06-07 06:24:04       91 阅读

热门阅读

  1. 【Android】点击图片获取点击位置在图片中的位置

    2024-06-07 06:24:04       30 阅读
  2. electron录制工具-准备录制mask

    2024-06-07 06:24:04       27 阅读
  3. 一些关于科技的想法

    2024-06-07 06:24:04       33 阅读
  4. 使用docker直接运行不同版本nodejs命令

    2024-06-07 06:24:04       36 阅读
  5. Centos7安装Docker和DockerCompose

    2024-06-07 06:24:04       30 阅读
  6. PostgreSQL的视图pg_stat_database

    2024-06-07 06:24:04       31 阅读
  7. Open MV 人眼识别和瞳孔识别

    2024-06-07 06:24:04       33 阅读
  8. PostgreSQL的视图pg_locks

    2024-06-07 06:24:04       30 阅读
  9. python里装饰器的作用是什么

    2024-06-07 06:24:04       27 阅读