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


相关推荐

  • loadrunner视频教程百度云_loadrunner使用教程图文

    loadrunner视频教程百度云_loadrunner使用教程图文播客视频,java虚拟用户http://www.boobooke.com/v/bbk1900/LR动态链接库小布老师视频:测试工具概述,兼LoadRunner介绍-1-4http://www.boobooke.com/v/bbk1046http://www.boobooke.com/v/bbk1047http://www.boobooke.com/v/

    2022年10月14日
    0
  • 什么是代码_大专程序员有人要吗

    什么是代码_大专程序员有人要吗什么是代码,什么是数据。代码是能够处理其他数据的数据,而数据是储存信息的数据。数据有时能够变成代码,代码也可以变成数据。甚至,一段数据中某一段,都可以单独拿出来,通过执行器执行(执行器,比如exe的执

    2022年8月1日
    3
  • S3C2440—UART原理简介

    S3C2440—UART原理简介通用异步收发器简称UART,即“UniversalAsynchronousReceiverTransmitter”     s3c2440提供了三个UART端口,它们都可以通过查询、中断和DMA方式传输数据,而且每个UART都分别有一个64个字节的接收FIFO和一个64个字节的发送FIFO。UART由波特率发生器、发送器、接收器和控制逻辑组成,使用系统时钟可以达到115.2Kbit

    2022年5月27日
    30
  • QTreeView使用总结7,右键菜单

    QTreeView使用总结7,右键菜单1,简介最开始我要做右键菜单时,理所当然的想到的是右键单击的信号,这样是可以的。后来发现原来Qt给QWidget提供了单独的菜单信号:voidcustomContextMenuRequested(constQPoint&pos);不过需要先设置菜单策略,使用接口:setContextMenuPolicy(Qt::CustomContextMenu);2,菜单效果下面介绍一个示例,实现…

    2022年5月9日
    33
  • 解决windowlocationhref不跳转的 BUG「建议收藏」

    解决windowlocationhref不跳转的 BUG「建议收藏」今晚写了代码发现了一个小BUG,记录下。<form>———<p><!–下面按钮–><divclass="footerContainer"><buttonid="nextStep"onclick="skip()&q

    2022年7月15日
    15
  • java工程师青春饭吗_Java工程师是青春饭吗?

    java工程师青春饭吗_Java工程师是青春饭吗?首先来说说,为什么会有些开发人员会被裁掉呢?因为Java行业是竞争力比较大的行业,由于现在社会上的各种对Java行业的宣传,现在越来也多的年轻人学习Java技能并想找Java相关的工作,这就使得一些人如果找到工作后不好好工作浑水摸鱼就很容易被别的年轻人挤掉工作岗位。其次Java开发并不是一门熟能生巧的工作,Java开发技术日新月异,更新换代很快,所以并不是你掌握好几项Java技术并找到工作后就能安…

    2022年7月7日
    28

发表回复

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

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