您的位置 首页 php

nginx+php-fpm+ php 运行一个简单的登录程序

文章目录

  • 概述
  • 功能分析
  • 程序结果

概述

本文主要介绍用php + php-fpm + nginx 实现一个简单的登录程序。
目录结构如下:

功能分析

logon.html是页面文件,内容如下:

logon.html比较简单,主要就是两个文本框,用于接收账号和密码,点击submit后会进入logon.php中。

 <html>
    <head>
    <title>login</title>
    <style>
    #dog{
        text-align:center;
    }  
    </style>
    </head>
    <body>
    <div id="dog">
    <form method="POST" action="logon.php">
        admin<br>
        account:<input type="username" name="username"><br>
        password:<input type="password" name="upass"><br>
    <input type="submit" value="logon">
    </form>
    </div>
    </body>                                                                                                                                                                  
<html>
  

logon.php 是登录的逻辑,这里采用 硬编码 ,因为只是一个demo 程序,没有去连数据库。
logon.php

 <?php                                                                                                                                                                        
if ($_POST["username"]=='admin'&& $_POST["upass"]=='111111')
{
    echo "login success";
}
else
{
    echo "login failed";
}
 
?>
  

最后的话配置nginx 配置文件,主要增加如下的两处:

第一处用于静态文件

 location  /{
     root  /home/test;
}  

第二处用于php文件

  location ~ \.php$ {
       root    /home/test/module;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
 }  

完整的nginx 配置文件如下所示:

 
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location  /{
            root  /home/test;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root    /home/test/module;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
  

程序结果

登录界面,输入admin/111111

可以看到,登录成功了。

到此为止,这个简单的phpdemo代码就完整了。

文章来源:智云一二三科技

文章标题:nginx+php-fpm+ php 运行一个简单的登录程序

文章地址:https://www.zhihuclub.com/149916.shtml

关于作者: 智云科技

热门文章

网站地图