linux 如何配置 nginx

云服务器,优惠购买地址:https://www.rainyun.com/MzgyMDA3_

1. 查看 Nginx 状态

使用以下命令查看 Nginx 的状态:

systemctl status nginx

如果状态为 Active: active (running),则表示 Nginx 正常运行。

例如,命令输出如下:

[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 aux | grep nginx

此命令会列出所有与 Nginx 相关的进程。

3. 检查 Nginx 配置文件

要确保 Nginx 配置文件没有问题,可以运行以下命令进行检查:

nginx -t

如果配置没有问题,输出将显示 successful

4. 查看 Nginx 版本

要查看当前安装的 Nginx 版本,可以使用以下命令:

nginx -v

如果你希望查看更详细的版本信息,可以使用:

nginx -V

5. 修改 Nginx 配置

要修改 Nginx 配置文件,可以使用编辑器打开配置文件:

vim /etc/nginx/nginx.conf

例如,你可以将容器端口 8090 指向域名,添加以下配置:

server {
      listen 80;
      server_name www.tieyongjie.cn;  # 替换为您的域名
  
      location / {
         proxy_pass http://localhost:8090;  # 指向 Docker 容器的端口 8090
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
      }
}

保存并退出编辑器后,重新加载 Nginx 配置以应用更改:

systemctl reload nginx

6. 设置 Nginx 开机自启动

如果你希望 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

云服务器,优惠购买地址:https://www.rainyun.com/MzgyMDA3_


🎉 云服务器,优惠购买地址:https://www.rainyun.com/MzgyMDA3_ 🎉

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇