CentOS rpm安装Nginx和配置

CentOS rpm安装Nginx和配置CentOSrpm安装Nginx和配置官方下载地址:http://nginx.org/en/download.html介绍Nginx(“enginex”)是一款由俄罗斯的程序设计师IgorSysoev所开发高性能的Web和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。rpm包安装#安装nginx,rpm安装#rpm安装nginx包rpm-Uvh–force–nodepsnginx-1.16.1-1.el7.ngx.x86_64.rpm#查看启

大家好,又见面了,我是你们的朋友全栈君。

CentOS rpm安装Nginx和配置

官方下载地址: http://nginx.org/en/download.html

介绍

Nginx(“engine x”)是一款由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

rpm包安装

#安装nginx,rpm安装
#rpm安装nginx包
rpm -Uvh --force --nodeps nginx-1.16.1-1.el7.ngx.x86_64.rpm

#查看启动状态
systemctl status nginx

显示如下:
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2021-11-26 11:12:41 CST; 5 days ago
     Docs: http://nginx.org/en/docs/
  Process: 1379 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 1543 (nginx)
    Tasks: 5
   CGroup: /system.slice/nginx.service
           ├─1543 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           ├─1544 nginx: worker process
           ├─1546 nginx: worker process
           ├─1547 nginx: worker process
           └─1548 nginx: worker process

1126 11:12:41 liang systemd[1]: Starting nginx - high performance web server...
1126 11:12:41 liang systemd[1]: Started nginx - high performance web server.

#启动
systemctl start nginx

#重启
systemctl restart nginx

#开机自启动服务
systemctl enable nginx

#查看开机启动状态 enabled:开启, disabled:关闭
systemctl is-enabled nginx

安装完后在 修改 /etc/nginx/conf.d/default.conf 配置文件,参考内容如下:

vim /etc/nginx/conf.d/default.conf

server { 
   
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log /var/log/nginx/host.access.log main;


     location /ui { 
   
        alias   /data/dist;
        index  index.html index.htm;
     }
     
     location /file/ { 
   
         root   /home/data/;
        index  index.html index.htm;
     }    
    # websocket配置wss
    location /liangws/ { 
   
        proxy_pass http://192.168.0.19:8080/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Remote_addr $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_read_timeout 600s;
    }

    location ~ /gat { 
   
        proxy_set_header Host  $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:18080 ;
    }

    #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   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ { 
   
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ { 
   
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht { 
   
    # deny all;
    #}
}

注意:静态文件下载,需要依赖nginx,我们需要将这些文件放到 nginx配置文件中的 /home/data/aaa 对应的目录下。

启动服务配置

cat /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/135679.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • WireShark 过滤语法

    WireShark 过滤语法

    2021年8月15日
    78
  • js数组添加数据和删除数据

    js数组添加数据和删除数据1.栈方法(1).push():向Array的末尾添加若干元素;(2).pop()函数:删除数组中的最后一个数据vararr=[1,2,3,4];arr.push(6,7,8);//push压栈向数组末尾添加元素console.log(arr);//arr=[1,2,3,4,6,7,8];vararr1…

    2022年4月30日
    167
  • hashmap 遍历 取值「建议收藏」

    hashmap 遍历 取值「建议收藏」Map<String,String>gettext=newHashMap<String,String>();gettext=link.linkGet(“F://htmls/compare/98.15.3.html”,”utf-8″);;//给以一个hashpmap实例给gettextItera…

    2025年9月12日
    5
  • 光纤交换机zone配置

    光纤交换机zone配置一、CentOS下查看PortName1、命令cat/sys/class/fc_host/host[N]/port_state,显示online则证明链路状态正常2、命令cat/sys/class/fc_host/host[N]/port_name,获取客户端HBA卡PortName二、AIX下查看WWNName1、查看系统中有效的光纤卡$lsdev-Ccadapter-Sa|grepfcs3、查看光纤卡WWNName$ls…

    2022年5月11日
    71
  • 图像滤波算法总结[通俗易懂]

    图像滤波算法总结[通俗易懂]该篇主要是对图像滤波算法一个整理,主要参考的大神的博客:https://blog.csdn.net/qq_15606489/article/details/527554441:图像滤波既可以在实域进行,也可以在频域进行。图像滤波可以更改或者增强图像。通过滤波,可以强调一些特征或者去除图像中一些不需要的部分。滤波是一个邻域操作算子,利用给定像素周围的像素的值决定此像素的最终的输出值。图像…

    2022年6月10日
    34
  • 第一个Java项目———Java实现简单图书管理系统(GUI)

    第一个Java项目———Java实现简单图书管理系统(GUI)暑假写了个图书管理系统,编译器用的是eclipse,加入了WindowBuilder插件做界面(做的特丑),数据库用的是MySQL。实现了图书的查询,借阅,归还,删除,增加。用户的删除,查询。分为管理员和用户。一,程序整体框架从项目开始,无从下手,随着学习的深入,慢慢的熟悉了开发流程,先把整体框架搭起来,这个过程可以减少后续的一些麻烦,做数据库前先想好需求,…

    2022年7月15日
    12

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号