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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • tomcat官网如何下载低版本的tomcat

    tomcat官网如何下载低版本的tomcat

    2021年7月17日
    87
  • 时间序列 介绍(一)「建议收藏」

    时间序列 介绍(一)「建议收藏」引言DT时代,数据的重要性已经不必再强调了。最近几年深度学习,机器学习,人工智能炙手可热,各行各业的人,无论是单纯的蹭热度也好,还是真的想做一些改变,都在往这三个概念上靠,但我相信,绝大部分人是真

    2022年8月4日
    9
  • jQuery validationEngine自定义提醒

    jQuery validationEngine自定义提醒在网上看了好多自定义验证样式,好多都是不是自己想要的!打开源码,看了一下挺简单的!将下面的样式添加到页面上就可以实现黑色主题的提醒!想要什么样式基本都可以自己修改了!很方便/*验证样式*/.formError.formErrorContent{ width:100%; /*错误提示框颜色*/ background:#000; position:rela

    2022年10月3日
    4
  • 微服务:注册中心ZooKeeper、Eureka、Consul 、Nacos对比

    微服务:注册中心ZooKeeper、Eureka、Consul 、Nacos对比前言服务注册中心本质上是为了解耦服务提供者和服务消费者。对于任何一个微服务,原则上都应存在或者支持多个提供者,这是由微服务的分布式属性决定的。更进一步,为了支持弹性扩缩容特性,一个微服务的提供者的数量和分布往往是动态变化的,也是无法预先确定的。因此,原本在单体应用阶段常用的静态LB机制就不再适用了,需要引入额外的组件来管理微服务提供者的注册与发现,而这个组件就是服务注册中心。CAP理论…

    2022年6月4日
    33
  • 如何部署服务器虚拟化,vmware服务器虚拟化方案(vmware虚拟化平台部署)

    如何部署服务器虚拟化,vmware服务器虚拟化方案(vmware虚拟化平台部署)服务器虚拟化平台方案主要的有三种 特点分别如下 1 思杰 CitrixXenSer XenCenter 是 Citrix 的虚拟化图形接口管理工具 可在同一界面 管理多台的 XenServer 服务 以前见过一台服务器安装虚拟服务器 然后可以装 N 个系统 又节约硬件 又 1VMwareESXSe 的安装 VMwareESXSer 需要 2GB 的内存 在开始测试的时候 为 ESXSer

    2025年9月5日
    3
  • SpringBootTest使用MockMvc测试Controller

    SpringBootTest使用MockMvc测试Controllerimportstaticorg.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;importstaticorg.springframework.test.web.servlet.result.MockMvcResultMatchers.*;@RunWith(SpringRunner.class)@…

    2022年5月5日
    49

发表回复

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

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