欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux nginx的安装以及环境配置

程序员文章站 2022-04-01 11:23:47
1、下载nginx压缩包下载:nginx官网也可以直接使用wget命令下载,指令如下所示(请根据自己的需求进行下载):# wget http://nginx.org/download/nginx-1.14.2.tar.gz注意:这一步最好在自己的目标目录进行操作,我一般是把压缩包下载到/usr/local目录下。2、配置nginx安装所需的环境(1)安装相关依赖# yum install readline-devel pcre-devel openssl-devel gcc -y (2)...

1、下载nginx压缩包

下载:nginx官网
也可以直接使用wget命令下载,指令如下所示(请根据自己的需求进行下载):

# wget http://nginx.org/download/nginx-1.14.2.tar.gz

注意:这一步最好在自己的目标目录进行操作,我一般是把压缩包下载到/usr/local目录下。

2、配置nginx安装所需的环境

(1)安装相关依赖

# yum install readline-devel pcre-devel openssl-devel gcc -y 

(2)解压与编译安装**

# tar zxvf nginx-1.14.2.tar.gz
# cd nginx-1.14.2
//安装相应模块
# ./configure --prefix=/usr/local/nginx  \
--with-stream  \
--with-stream_ssl_module \
--with-threads \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module 
--user=nginx \ 
--group=nginx  &>/dev/null
\\gmake -j 加速Linux程序编译
# gmake -j 2 &>/dev/null && gmake install &>/dev/null

(3)创建相应用户及目录

# useradd -s /sbin/nologin -M nginx
# mkdir -p /data/logs/nginx
//创建存放每个站点文件的目录
# mkdir /usr/local/nginx/conf/vhost

(4)主配置文件nginx.conf中指定包含其他扩展配置文件,从而简化nginx主配置文件,实现多个站点功能

//备份原配置文件,直接用改写好的配置文件覆盖
# cp /usr/local/nginx/conf/nginx{,.`data +F`}
# cat > /usr/local/nginx/conf/nginx.conf << \EOF
user  nginx nginx;
worker_processes  4;

pid        logs/nginx.pid;

events {
    use epoll;
    worker_connections  65535;
    multi_accept        on;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    #charset  utf-8;
    server_names_hash_bucket_size 128;
    large_client_header_buffers 4 64k;
    client_header_buffer_size 32k;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                       '$upstream_addr $upstream_response_time $request_time';
    sendfile       on;
    tcp_nopush     on;
    client_max_body_size 1024m;
    tcp_nodelay    on;
    keepalive_timeout  100;
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 8k;
    gzip_http_version 1.1;
    gzip_types       text/* text/css application/javascript application/x-javascript;
    server_tokens off;
#创建多个配置文件     
include /usr/local/nginx/conf/vhost/*.conf;
}
EOF 

(5)例如配置zabbix需要站点nginx虚拟目录

# cat > /usr/local/nginx/conf/vhost/web.zabbix.com.conf << \EOF 
server {
    listen       80;
    server_name  web.zabbix.com;
    access_log   /data/logs/nginx/zabbix_access.log  main;
    error_log    /data/logs/nginx/zabbix_error.log   error;
    location / {
        root   /data/web/zabbix;
        index  index.php index.html index.htm ;
    }
    location ~ \.php$ {
        root   /data/web/zabbix;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name ;
        fastcgi_index  index.php;
        include        fastcgi_params;
    }
}
EOF

(6)授予权限

# chown -R nginx.nginx /usr/local/nginx/

(7)检查配置语法及启动

# /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx  (-s reload重新加载)

本文地址:https://blog.csdn.net/chj_1224365967/article/details/107597678

相关标签: Nginx