Skip to main content

Webmin 1.8.10 Nginx 502 on Reboot

因为Webmin1.8.10没有自动创建启动文件的bug,会导致nginx在重新启动服务器之后无法正确打开socket,从而无法正确执行PHP。解决方法如下:

在配置文件中找到socket:

server {  
        server_name casinopb.com www.casinopb.com;
        listen 192.74.244.100;
        root /home/healpb/public_html;
        index index.html index.htm index.php;
        access_log /var/log/virtualmin/healpb.com_access_log;
        error_log /var/log/virtualmin/healpb.com_error_log;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE nginx;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param SCRIPT_FILENAME /home/healpb/public_html$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param DOCUMENT_URI $document_uri;
        fastcgi_param DOCUMENT_ROOT /home/healpb/public_html;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param HTTPS $https;
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/php-nginx/147421583324055.sock/socket;
        }
        listen 192.74.244.100:443 default ssl;
        ssl_certificate /home/casinopb/ssl.cert;
        ssl_certificate_key /home/casinopb/ssl.key;
    }

我们需要找到的就是unix:/var/php-nginx/147421583324055.sock/socket

在/etc/init.d创建启动文件

为了和webmin版本保持统一的命名规则,取名字最好是php-fcig-domain-com

#!/bin/sh
### BEGIN INIT INFO
# Provides: php-fcgi-example-com
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# PHPRC -> 加载的配置文件
### END INIT INFO

case "$1" in  
'start')  
    su 执行的用户 -c PHP_FCGI_CHILDREN\=4\ PHPRC\=\/home\/casinopb\/etc\/php7\.0\ \/usr\/bin\/php\-loop\.pl\ \/usr\/bin\/php\-cgi\ \-b\ \/var\/php\-nginx\/socket路径中的ID\.sock\/socket\ \>\>\/home\/casinopb\/logs\/php\.log\ 2\>\&1\ \<\/dev\/null\ \&\ echo\ \$\!\ \>\/var\/php\-nginx\/socket路径中的ID\.php\.pid
    RETVAL=$?
    ;;
'stop')  
    su 执行的用户 -c kill\ \`cat\ \/var\/php\-nginx\/socket路径中的ID\.php\.pid\` ; sleep 1
    RETVAL=$?
    ;;
'restart')  
    $0 stop ; $0 start
    RETVAL=$?
    ;;
*)
    echo "Usage: $0 { start | stop }"
    RETVAL=1
    ;;
esac  
exit $RETVAL  

设置文件权限为755并启动,即可正常使用nginx执行php。