新手问题 如何判断生产环境下 Nginx 是否正常工作

SunA0 · May 08, 2020 · Last by xiayuanyin replied at May 13, 2020 · 3754 hits

最近瞎摸了一下 nginx+passenger 在阿里云部署生产环境

项目下敲命令 passenger start -e production -d 也跑起来了

但是 nginx.conf 里写的用 80 端口。查的时候 80 端口是阿里云的服务在占用

所以不明白 nginx 是否有在工作,也有用命令去看进程

nginx.conf

server {
        listen       80;
        server_name  ip;
        root /root/project/public
        passenger_enabled on;
        location / {
            root   html;
            index  index.html index.htm;
        }
}

lsof -i:80

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
AliYunDun 883 root   22u  IPv4  19135      0t0  TCP ubuntu18.04:59914->100.100.30.26:http (ESTABLISHED)

lsof -i:3000

COMMAND     PID  USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nginx-1.1 12800 xx    5u  IPv4 1106451      0t0  TCP *:3000 (LISTEN)
nginx-1.1 12805 xx    5u  IPv4 1106451      0t0  TCP *:3000 (LISTEN)

ps -ef | grep nginx

xx    12800     1  0 May07 ?        00:00:00 nginx: master process /home/xx/.passenger/support-binaries/6.0.4/nginx-1.17.3 -c /tmp/passenger-standalone.ditppu/nginx.conf -p /tmp/passenger-standalone.ditppu
xx    12805 12800  0 May07 ?        00:00:00 nginx: worker process
xx    12812     1  0 May07 ?        00:00:00 /home/xx/.rvm/gems/ruby-2.4.1@blog/gems/passenger-6.0.4/buildout/support-binaries/PassengerAgent temp-dir-toucher /tmp/passenger-standalone.ditppu --cleanup --daemonize --pid-file /tmp/passenger-standalone.ditppu/temp_dir_toucher.pid --log-file /home/xx/project/log/passenger.3000.log --nginx-pid 12800
root     14906 14786  0 00:26 pts/2    00:00:00 grep --color=auto nginx

sudo service nginx status ?

Reply to ken

Unit nginx.service could not be found.那看来是没成功;谢谢

standalone 模式不用系统安装的 nginx,所以 nginx.conf 文件没用到

netstat -nltp (number, listen, tcp, programs)

Reply to xiayuanyin
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      309/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      837/sshd            
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      12800/nginx: master 
tcp        0      0 0.0.0.0:34893           0.0.0.0:*               LISTEN      19509/Passenger App 

意思就是用在了 3000 端口上?

增加一个 /status

server {
  location /status {
    access_log off;
    add_header Content-Type text/plain;
    return 200 'OK via Nginx';
  }
}

然后用 HTTP 访问 http://localhost/status 来验证

Reply to SunA0

意思是你的 nginx 就监听了 3000 端口

SunA0 closed this topic. 14 May 10:10
You need to Sign in before reply, if you don't have an account, please Sign up first.