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


相关推荐

  • 【从翻译mos文章】Weblogic AdminServer 启动fail,报错"unable to get file lock, will retry"

    【从翻译mos文章】Weblogic AdminServer 启动fail,报错"unable to get file lock, will retry"

    2022年1月1日
    57
  • conda 删除环境

    conda 删除环境condaremover Toremovethee ntest env

    2025年8月23日
    0
  • administrator改名字_计算机名和用户名

    administrator改名字_计算机名和用户名重命名计算机必须以管理员或Administrators组成员身份登录才能完成该过程。如果计算机与网络连接,则网络策略设置也可以阻止您完成此步骤。在控制面板中打开系统。在“计算机名称”选项卡,单击“更改”。在“计算机名”下键入计算机的新名称,然后单击“确定”。如果计算机是域的成员,则提示您提供用户名和用户密码才能重命名域中的计算机。注意要打开“系统”,请单击“开始”,指向“设置”,单击“控制面…

    2022年10月14日
    2
  • Java 如何抛出异常、自定义异常[通俗易懂]

    一、异常的抛出1、定义:一个方法不处理这个异常,而是调用层次向上传递,谁调用这个方法,这个异常就由谁来处理。2、throw:将产生的异常抛出(强调的是动作),抛出的既可以是异常的引用,也可以是异常对象。(位置:方法体内)3、throws:如果一个方法可能会出现异常,但没有能力处理这种异常,可以在方法声明处用throws子句来声明抛出异常。用它修饰的方法向调用者表明该方法可能会抛出异

    2022年4月14日
    44
  • 如何创建springboot项目[通俗易懂]

    如何创建springboot项目[通俗易懂]前言本片博客记录快速创建springboot工程的两种方式。一种是使用maven创建,一种是使用springinitializr创建。开发环境JDK1.8、IDEA、maven。SpringBoot优点可快速构建spring应用直接嵌入tomcat、jetty、undenrtow服务器(无须部署war文件)提供依赖启动器(starter)简化构建配置极大程度的自动化配置Spring和第三方库提供生产就绪功能,例如指标监控检测、外部检测极少代码生成和XML配置使用maven创建Spr

    2022年8月31日
    2
  • Flash停止支持?不用愁!![通俗易懂]

    Flash停止支持?不用愁!![通俗易懂]2020年的最后一天,Flash华丽谢幕与我们告别……作为一名4399的忠实玩家,真是心痛不已……所以,今天告诉大家几种让Flash重新工作的方式:1.安装“中国版Flash”:目前,中国已经

    2022年8月1日
    14

发表回复

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

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