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
相关推荐
2301_810154554 分钟前
VM中CentOS 7密码重置
linux·运维·centos
zhaqonianzhu11 分钟前
Linux GPIO 使用 Pinctrl 及 Gpiolib 通俗详解
linux·安卓
网硕互联的小客服20 分钟前
408 Request Timeout:请求超时,服务器等待客户端发送请求的时间过长。
运维·服务器
王伯安呢23 分钟前
告别线缆束缚!AirDroid Cast 多端投屏,让分享更自由
运维·服务器·教程·投屏·airdroid cast·多端互投
逍遥浪子~27 分钟前
搭建本地gitea服务器
运维·服务器·gitea
骄傲的心别枯萎29 分钟前
RV1126 NO.16:通过多线程同时获取H264和H265码流
linux·c++·音视频·rv1126
空灵之海31 分钟前
Ubuntu系统安全合规配置
linux·ubuntu·系统安全·1024程序员节
喜欢你,还有大家35 分钟前
FTP文件传输服务
linux·运维·服务器·前端
Bi1 小时前
Dokploy安装和部署项目流程
运维·前端
czhc11400756631 小时前
LINUX99 centos8:网络 yum配置;shell:while [ $i -ne 5 ];do let i++ done
linux