centos 7.X系统安装配置nginx

1.安装包准备

nginx官网https://nginx.org/en/download.html下载压缩包,一般下载最新稳定版本即可。

2.安装依赖

yum install -y gcc

yum install -y pcre pcre-devel

yum install -y zlib zlib-devel

yum install -y openssl openssl-devel

3.安装包解压到喜欢的目录

[root@VM-0-3-centos ~]# tar -zxvf /yzmeta/tool/nginx-1.24.0.tar.gz -C /etc

4.执行配置指令

注:--prefix=/etc/nginx 意思是将安装在/etc/nginx目录,需要事先通过命令创建nginx目录(sudo mkdir nginx)

[root@VM-0-3-centos ~]# cd /etc/nginx-1.24.0

[root@VM-0-3-centos nginx-1.24.0]# sudo ./configure --prefix=/etc/nginx --with-http_ssl_module --with-stream --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module

# 配置configure --prefix 代表安装的路径;

--with-http_ssl_module 安装ssl;

--with-http_stub_status_module查看nginx的客户端状态;

5.执行安装指令

[root@VM-0-3-centos nginx-1.24.0]# sudo make & make install

6.创建nginx用户组

   注:nginx-1.24.0目录只是解压缩包所在路径,实际安装配置路径在/etc/nginx目录下。

创建nginx用户组(为了安全添加nginx用户和组,以便以后以nginx用户的身份运行nginx程序,而非root)进入到nginx中。

[root@VM-0-3-centos nginx-1.24.0]# cd /etc/nginx

[root@VM-0-3-centos nginx]# groupadd -r nginx

[root@VM-0-3-centos nginx]# useradd -r -g nginx nginx

或[root@VM-0-3-centos nginx]# useradd nginx -s /sbin/nologin

7.配置nginx.conf配置文件

user nginx;

worker_processes 10;        # 线程数,可以设置成auto自动,也可根据本机硬件线程数合理设置

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

#pid        logs/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {

    worker_connections  1024;

}

http {

    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  /var/log/nginx/access.log  main;

sendfile            on;

    server_tokens   off;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;

    include       mime.types;

    default_type  application/octet-stream;

    include /etc/nginx/conf/conf.d/*.conf;

    server {

        #listen       80 default_server;

        #listen       [::]:80 default_server;

#默认端口改成780

listen       780 default_server;

        listen       [::]:780 default_server;

        server_name  _;

        root         /usr/share/nginx/html;

include /etc/nginx/conf/default.d/*.conf;

    return 301 https://$host$request_uri;

        error_page 404 /404.html;

        location = /404.html {

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }

server {

        listen       7443 ssl http2 default_server;

        listen       [::]:7443 ssl http2 default_server;

#修改默认端口

        #listen       7443 ssl;

        #listen       [::]:7443 ssl;

        #server_name  demo.hop.com;

        server_name   wx.hzfy.com.cn;

        #server_name  localhost;

        root         /usr/share/nginx/html;

      client_max_body_size 500M;

        #ssl_certificate 1_demo.hop.com_bundle.crt;

        #ssl_certificate_key 2_demo.hop.com.key;

        ssl_certificate wx.hzfy.com.cn.pem;

        ssl_certificate_key wx.hzfy.com.cn.key;

        ssl_session_cache shared:SSL:1m;

        ssl_session_timeout  5m;

#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

#       ssl_ciphers HIGH:!aNULL:!MD5;

        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

        ssl_prefer_server_ciphers on;

#       # Load configuration files for the default server block.

        include /etc/nginx/conf/default.d/*.conf;

        location / {

try_files  $uri $uri/ /index.html;

        }

location /wx {

root /yzmeta/html/;

try_files $uri $uri/ @router;

index index.html;

}

###########################

location /haphone {

try_files $uri $uri/ @harouter;

index index.html;

}

location @harouter {

#root /yzmeta/html/;

rewrite ^.*$ /haphone/index.html last;

}

    

#location /haapi {

    #        proxy_pass http://localhost:9900/rdb;

    #}

location /api {

             proxy_pass http://localhost:9900/rdb;

        }

  

location /rdb {

proxy_pass http://localhost:9900/rdb;

}

        error_page 404 /404.html;

        location = /404.html {

        }

        error_page 500 502 503 504 /50x.html;

        location = /50x.html {

        }

    }

}

8.nginx使用命令

1查看nginx服务及配置文件安装目录

[root@VM-0-3-centos ~]# find / -name nginx

2直接打开默认目录

[root@VM-0-3-centos ~]# cd /etc/nginx
[root@VM-0-3-centos nginx]# ll

3输入nginx,开启服务

[root@VM-0-3-centos ~]# cd /etc/nginx/sbin                    #进入nginx启动文件路径

[root@VM-0-3-centos ~]# sudo ./nginx                             #启动nginx服务

4查询进程

        ps -aux|grep nginx

(5)查询nginx状态

         nginx -t

6关闭nginx

        nginx -s stop

7重启

        nginx -s reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

春化雨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值