首页 > 系统相关 >Centos 安装nginx

Centos 安装nginx

时间:2023-11-20 15:36:45浏览次数:51  
标签:Centos header 安装 nginx cl8023 proxy conf com

一、添加Nginx到YUM源

 sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

二、安装nginx

# sudo yum install -y nginx

三、启动nginx

# sudo systemctl start nginx.service

四、开机启动

# sudo systemctl enable nginx.service

五、nginx配置信息

网站文件默认目录:/usr/share/nginx/html

网站默认站点配置:/etc/nginx/conf.d/default.conf

自定义Nginx站点配置文件存放目录:/etc/nginx/conf.d/

Nginx全局配置:/etc/nginx/nginx.conf

nginx启动:# nginx -c nginx.conf

常用操作:

start nginx  //启动

nginx -s stop // stop是快速停止nginx,可能并不保存相关信息

nginx -s quit // quit是完整有序的停止nginx,并保存相关信息

nginx -s reload // 当配置信息修改,需要重新载入这些配置时使用此命令

nginx -s reopen // 重新打开日志文件

nginx -v // 查看Nginx版本

配置nginx.conf反向代理多个node项目
启动多个node项目,分别监听不同端口,如
项目1,监听端口3000,为博客项目,域名访问 www.cl8023.com 或 cl8023.com
项目2,监听端口8023,为游戏项目,域名访问 game.cl8023.com
在阿里云服务区控制台开放端口3000和8023,(80端口是必须的,nginx监听)
绑定二级域名 game.cl8023.com,添加域名解析
记录类型:A
主机记录:game
解析线路:默认
记录纸:IP地址
TTL至:10分钟(默认)
修改nginx配置
进入目录 /etc/nginx 修改配置文件nginx.conf

// server 内容替换为
    server {
        listen 80;
        server_name game.cl8023.com;
        location / {
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:8023;
            proxy_redirect     off;
            proxy_set_header   X-Real-IP       $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

    server {
        listen 80;
        server_name cl8023.com www.cl8023.com;
        # 解决刷新404的问题
        location /blog {
            try_files $uri $uri/ /index.html;
        }
        location / {
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:3000;
            proxy_redirect     off;
            proxy_set_header   X-Real-IP       $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

重启nginx

service nginx restart

标签:Centos,header,安装,nginx,cl8023,proxy,conf,com
From: https://www.cnblogs.com/sili-future/p/17844051.html

相关文章

  • golang环境和第三方爬虫包下载安装一把成
    复制代码在CentOS7.6中命令行中全部粘贴执行,golang环境和第三方爬虫包全部安装一把成。wgethttps://golang.google.cn/dl/go1.21.4.linux-amd64.tar.gztar-zxvfgo1.21.4.linux-amd64.tar.gz-C/usr/local/cat>>.bash_profile<<"EOF"exportGOROOT=/usr/local/goexpo......
  • centos9升级openssh 9.4p1
    本文参考:https://www.cnblogs.com/wenxiao1-2-3-4/p/16481300.html#!/bin/shcd/etc/yum.repos.dmkdirbackupmvCent*backupwget-O/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-9.repoyum-ycleanallyum-ymakecache #以上设置云源cd......
  • 阿里云 ecs绑定辅助网卡,一个ECS服务器绑定多个IP ,用于centos,其他系统可以参考
    1、进入实例详情,选择网络与安全->弹性网卡  2、创建网卡3、然后创建好之后,绑定实例,我图1的是已经绑定好了的  4、进入弹性公网IP:https://vpc.console.aliyun.com/eip/ap-southeast-1/eips 5、购买ip,建议选择按量付费,没有带宽限制,购买完成后绑定刚刚创建的辅助......
  • Centos7 使用yum从第三方仓库安装Python3.8
    环境:CentOSLinuxrelease7.9.2009起因:Centos7自带Python2.7.5版本。而默认的YUM安装的python3是3.6版本,遂升级到3.8版本。installPython3.8yuminstall-ycentos-release-scl#仓库注册yuminstall-yrh-python38which#安装python3.8#创建软连接ln-s/opt......
  • 从显卡驱动,到pytoch的安装
    有些东西,可能当时觉得理解了,实际上还是模模糊糊的显卡驱动最开始我的电脑上是没有nvidia的控制面板的,所以先安装的nvidia的驱动官网: nvidia-smi如果显示nvidia不是系统变量,说明驱动安装好了之后,没有添加到path中,将C:\ProgramFiles\NVIDIACorporation\NVSMI添加到系统pat......
  • MySQL安装
    注:下面的操作都是Windows下进行下载地址:https://dev.mysql.com/downloads/mysql/1.官网下载2、针对操作系统的不同下载不同的版本 3.解压4.添加环境变量在文件夹中找到mysql.exe文件复制路径到path中5.初始化mysqld--initialize-insecure6.启动sql服务mysqld......
  • Liunx 安装keepalived
    1.官网下载 keepalived-2.2.2.tar.gz  移动到 /usr/soft/keepalived  然后进行解压     tar-zxvfkeepalived-2.2.2.tar.gz 2.配置   进入目录[root@localhostkeepalived]#cd/usr/soft/keepalived/keepalived-2.2.2[root@localhostkeepali......
  • Centos7 安装MySQL详细步骤
    1.1MySQL安装1.1.1下载wget命令yum-yinstallwget1.1.2在线下载mysql安装包wgethttps://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm1.1.3安装MySQLrpm-ivhmysql57-community-release-el7-8.noarch.rpm1.1.4安装mysql服务首先进入cd/et......
  • sysbench 安装 postgres 测试环境( Connection to database failed: SCRAM authenticat
    报错Connectiontodatabasefailed:SCRAMauthenticationrequireslibpqversion10orabove的解决方案1、下载安装包https://gitee.com/xiaohai008/postgresql10-devel2、安装yuminstall-ylibiculibicu-develrpm-ivhpostgresql10-10.23-1PGDG.rhel7.x86_64.rpmrp......
  • oracle 轻量化包安装,使用第三方客户端
    轻量版客户端工具包:此方式适用于NavicatPremium、PLSQL、DBeaver等客户端工具的,如果其他程序(自己开发的程序,中间件等)要使用的话,还是要安装完整版得客户端。下载地址;64位客户端工具:https://download.oracle.com/otn_software/nt/instantclient/1912000/instantclient-basic-wind......