linux配置nginx

1.查看nginx状态

bash 复制代码
systemctl status nginx

状态如果是Active: active (running)则是正常的

bash 复制代码
[root@hcss-ecs-9b96 ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2024-11-13 13:41:11 CST; 16min ago
  Process: 603696 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 603639 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 603637 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 603699 (nginx)
    Tasks: 3 (limit: 11427)
   Memory: 16.9M
   CGroup: /system.slice/nginx.service
           ├─603699 nginx: master process /usr/sbin/nginx
           ├─603700 nginx: worker process
           └─603701 nginx: worker process

2.查看Nginx进程

如果Nginx正在运行,您还可以使用ps命令来查看Nginx进程

bash 复制代码
ps aux | grep nginx

3.检查Nginx配置文件是否正确无误

bash 复制代码
nginx -t

4.查看Nginx的版本

bash 复制代码
nginx -v
# 如果查看更详细
nginx -V

5.修改nginx配置

bash 复制代码
vim /etc/nginx/nginx.conf

增加容器端口8090指向域名

bash 复制代码
server {
      listen 80;
      server_name www.tieyongjie.cn;  # 替换为您的域名

      location / {
         proxy_pass http://localhost:8090;  # 指向Docker容器的端口8080
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
    }

6. 设置开机自启动

bash 复制代码
# 设置 nginx 开机自启动
systemctl enable nginx
# 验证
systemctl is-enabled nginx

输出如下即表示开机自启动设置成功

复制代码
[root@hcss-ecs-9b96 ~]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@hcss-ecs-9b96 ~]# systemctl is-enabled nginx
enabled
相关推荐
知星小度S40 分钟前
系统核心解析:深入文件系统底层机制——Ext系列探秘:从磁盘结构到挂载链接的全链路解析
linux
2401_890443021 小时前
Linux 基础IO
linux·c语言
字节数据平台2 小时前
刚刚,火山引擎多模态数据湖解决方案发布大数据运维Agent
大数据·运维·火山引擎
智慧地球(AI·Earth)2 小时前
在Linux上使用Claude Code 并使用本地VS Code SSH远程访问的完整指南
linux·ssh·ai编程
原神启动12 小时前
Docker 场景化作业:生产环境容器操作实训
运维·docker·容器
云老大TG:@yunlaoda3602 小时前
如何通过华为云国际站代理商CSBS进行备份策略设置?
运维·数据库·华为云
老王熬夜敲代码3 小时前
解决IP不够用的问题
linux·网络·笔记
码里法3 小时前
centos安装nginx并配置https完整版
nginx·https·centos
zly35003 小时前
linux查看正在运行的nginx的当前工作目录(webroot)
linux·运维·nginx
QT 小鲜肉3 小时前
【Linux命令大全】001.文件管理之file命令(实操篇)
linux·运维·前端·网络·chrome·笔记