http-server
- 导航 (返回顶部)
- 1. Lighttpd
- 1.1 配置及验证
- 1.2 测试安装结果
- 1.3 基本日志记录
- 2. Nginx
- 2.1 安装和启动
- 2.2 配置及验证
- 2.3 FastCGI
- 3. Apache
- 3.1 安装和启动
- 3.2 配置及验证
- 3.3 用户目录
- 3.4 扩展PHP
- 1. Lighttpd
1. Lighttpd1.1 配置及验证1.2 测试安装结果1.3 基本日志记录
2. Nginx2.1 安装和启动2.2 配置及验证2.2.1 服务器块2.2.2 管理服务器入口2.3 FastCGI2.3.1 PHP实现2.3.2 nginx配置2.3.3 测试配置
3. Apache3.1 安装和启动3.2 配置及验证3.2.1 选项3.2.2 检查配置3.3 用户目录3.4 扩展PHP3.4.1 安装php-fpm3.4.2. 测试PHP是否有效
Apache | Nginx, nginx-mainline | Lighttpd | ╦═╦ | Php-fpm |
/etc/httpd/conf/httpd.conf | /etc/nginx/nginx.conf | /etc/lighttpd/lighttpd.conf | config | /etc/php/php-fpm.conf |
$ apachectl configtest | $ nginx -t |
$ lighttpd -t -f /etc/lighttpd/lighttpd.conf $ lighttpd -tt -f /etc/lighttpd/lighttpd.conf |
配置验证 |
../test.php <?php phpinfo(); |
/srv/http ; ~/public_html | /usr/share/nginx/html/ | /srv/http/ | root | |
httpd.service | nginx.service | lighttpd.service | service | php-fpm.service |
http://localhost/ http://localhost/~tom/ |
配置工具: https://nginxconfig.io/ |
示例配置: /usr/share/doc/lighttpd/config/ |
Other | http://127.0.0.1/test.php |
1. Lighttpd
相较于其他网页服务器,它占用的内存很少,且注重CPU负载量。
1.1 配置及验证
想要检查 lighttpd.conf 中的语法错误,可以使用以下命令来快速查找错误: $ lighttpd -t -f /etc/lighttpd/lighttpd.conf还可以进行更彻底的预检: $ lighttpd -tt -f /etc/lighttpd/lighttpd.conf示例配置文件在 /usr/share/doc/lighttpd/
1.2 测试安装结果
$ sudo echo 'Test-lighttpd' >> /srv/http/index.html
修改日志目录权限: $ sudo chown -R http:http /var/log/lighttpd启动服务: $ sudo systemctl start lighttpd然后就可以使用浏览器打开网址 localhost ,你应该能见到测试页面。 http://127.0.0.1/
1.3 基本日志记录
server.modules += (
"mod_access",
"mod_accesslog",
)
server.errorlog = "/var/log/lighttpd/error.log"
accesslog.filename = "/var/log/lighttpd/access.log"
2. Nginx
Nginx因为稳定,丰富的功能集,配置简单,资源占用低而闻名世界。这篇文章描述了如何设置nginx并且如何通过#FastCGI集成PHP.
2.1 安装和启动
注意:官方存储库中可用的所有 nginx 模块都需要nginx包(而不是nginx-mainline)作为依赖项。
在做出nginx与nginx-mainline决定之前,查看您可能需要/想要的任何模块列表可能是明智的。nginx-mainline 的模块可以在Arch User Repository 中找到。 $ sudo systemctl start nginx.servicehttp://127.0.0.1
访问到的默认页面是: /usr/share/nginx/html/index.html
2.2 配置及验证
更多细节和示例可以在https://wiki.nginx.org/Configuration和官方文档中找到。
下面的示例涵盖了最常见的用例。假定您使用文档的默认位置 (/usr/share/nginx/html)。如果不是这种情况,请替换您的路径。
提示: DigitalOcean 提供了一个Nginx 配置工具。 https://nginxconfig.io/
配置验证 $ sudo nginx -t2021/06/02 19:46:07 [warn] 2420#2420: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
2.2.1 服务器块
在下面的示例中,服务器侦听两个域的 IPv4 和 IPv6 端口 80 上的传入连接,domainname1.dom并且domainname2.dom:
/etc/nginx/nginx.conf
...
server {
listen 80;
listen [::]:80;
server_name domainname1.dom;
root /usr/share/nginx/domainname1.dom/html;
location / {
index index.php index.html index.htm;
}
}
server {
listen 80;
listen [::]:80;
server_name domainname2.dom;
root /usr/share/nginx/domainname2.dom/html;
...
}
重新启动 nginx.service以应用任何更改。
注意:通过设置像BIND或dnsmasq这样的 DNS 服务器来确保主机名是可解析的,或者查看网络配置#本地网络主机名解析。
2.2.2 管理服务器入口
创建以下文件夹: $ sudo mkdir /etc/nginx/sites-available
$ sudo mkdir /etc/nginx/sites-enabled
在sites-available文件夹下创建一个文件包含一个或更多服务器模块:
/etc/nginx/sites-available/example.conf
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
}
把include sites-enabled/*;放到http 模块的末尾:
/etc/nginx/nginx.conf
...
http {
...
include sites-enabled/*;
}
...
如果要启用一个网站, 只需要简单的创建一个符号链接: $ sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.conf如果要移除一个网站 $ sudo unlink /etc/nginx/sites-enabled/example.confReload/restart nginx.service 来让配置生效.
2.3 FastCGI
FastCGI 技术被引入 nginx 以与许多外部工具一起工作,例如Perl、PHP和Python。
2.3.1 PHP实现
安装 php-fpm并确保PHP已正确安装和配置。PHP-FPM 的主要配置文件是/etc/php/php-fpm.conf. 对于基本使用,默认配置应该足够了。 $ sudo systemctl status php-fpm.service
2.3.2 nginx配置
/etc/nginx/sites-available/example.conf
server {
root /usr/share/nginx/html;
location / {
index index.html index.htm index.php;
}
location ~ \.php$ {
# 404
try_files $fastcgi_script_name =404;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_passunix:/run/php-fpm/php-fpm.sock;
fastcgi_indexindex.php;
fastcgi_buffers8 16k;
fastcgi_buffer_size32k;
# fastcgi params
fastcgi_param DOCUMENT_ROOT$realpath_root;
fastcgi_param SCRIPT_FILENAME$realpath_root$fastcgi_script_name;
#fastcgi_param PHP_ADMIN_VALUE"open_basedir=$base/:/usr/lib/php/:/tmp/";
}
}
若需要处理PHP以外的文件(html, htm):
location ~ [^/]\.(php|html|htm)(/|$) {
...
}
非 .php 的PHP-FPM扩展处理都需要被直接加入到 /etc/php/php-fpm.d/www.conf:
security.limit_extensions = .php .html .htm
2.3.3 测试配置
要测试 FastCGI 实现,在web的根目录下(nginx.conf配置文件里server块的root项)创建包含如下信息的文件: test.php
<?php phpinfo();
在浏览器中导航此文件,您应该会看到包含当前 PHP 配置的信息页面。 http://127.0.0.1/test.phpPHP Version 8.0.6
SystemLinux tompc 5.12.8-arch1-1 #1 SMP PREEMPT Fri, 28 May 2021 15:10:20 +0000 x86_64
...
3. Apache
Apache HTTP 服务器,简称 Apache,是非常流行的Web服务器软件。
本文档描述了怎样安装设置 Apache 网页服务器。以及选择安装 PHP 并集成到Apache服务器中。
3.1 安装和启动
3.2 配置及验证
对于简单的设置,默认配置文件应该没问题。默认情况下,它会将目录/srv/http提供给访问您网站的任何人。 $ sudo systemctl start httpdApache 现在应该正在运行。通过在 Web 浏览器中访问http://localhost/。它应该显示一个简单的索引页面。
http://localhost/
3.2.1 选项
请参阅Apache 配置指令的完整列表和指令快速参考。
- https://httpd.apache.org/docs/trunk/mod/directives.html
- https://httpd.apache.org/docs/trunk/mod/quickreference.html
常用设置: /etc/httpd/conf/httpd.conf
- User http: 出于安全原因,若 Apache 由 root 用户(直接或通过启动脚本)启动,它就会切换到此 UID。默认用户是http,它是在安装过程中自动创建的。
- Listen 80: 这是 Apache 将侦听的端口。使用路由器访问互联网,您必须转发端口。 如果您想为本地开发设置 Apache,您可能希望它只能从您的计算机访问。 然后将此行更改为Listen 127.0.0.1:80.
- ServerAdmin you@example.com: 这是管理员的电子邮件地址,可以在例如错误页面上找到。
- DocumentRoot "/srv/http": 这是您放置网页的目录。可修改,但不要忘记也更改<Directory "/srv/http">,否则可能会收到403错误缺乏权限)。 将Require all denied行更改为Require all granted,或收到403。 注: DocumentRoot 目录及其父文件夹必须允许其他人执行权限(chmod o+x /path/to/DocumentRoot),否则您将收到403错误。
- AllowOverride None: <Directory>部分中的此指令会导致 Apache 完全忽略.htaccess文件。 请注意,这现在是 Apache 2.4 的默认设置,因此如果您打算使用.htaccess文件,则需要明确允许覆盖。 如果您打算mod_rewrite在.htaccess文件中使用或 其他设置,您可以允许该文件中声明的哪些指令可以覆盖服务器配置。
更多设置: /etc/httpd/conf/extra/httpd-default.conf
- ServerSignature Off: 关闭服务器的签名
- ServerTokens Prod: 隐藏 Apache 和 PHP 版本等服务器信息
3.2.2 检查配置
Syntax OK
3.3 用户目录
如果您不希望用户目录在 Web 上可用,请在/etc/httpd/conf/httpd.conf中注释掉以下行:
Include conf/extra/httpd-userdir.conf
$ chmod o+x ~/public_html
$ chmod -R o+r ~/public_html
$ ls -l /home/
drwxr-xr-x 21 tom users 4096 Jun 2 14:16 tom $ ls -l /home/tom/drwxr-xr-x 2 tom users 4096 Jun 2 14:17 public_html $ ls -l /home/tom/public_html/-rw-r--r-- 1 tom users 17 Jun 2 13:54 test.php
-rwxr-xr-x 1 tom users 48 Jun 2 08:17 tom.html
重新启动httpd.service以应用任何更改。另请参阅Umask#Set the mask value。 https://wiki.archlinux.org/title/Umask#Set_the_mask_value
3.4 扩展PHP
3.4.1 安装php-fpm
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/srv/http/$1
/etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
DirectoryIndex index.php index.html
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
并将其包含在以下内容的底部/etc/httpd/conf/httpd.conf:
Include conf/extra/php-fpm.conf
注意: sock和fcgi之间不允许有空格!localhost可以用任何字符串替换。
更多配置在这里: /etc/php/php-fpm.d/www.conf,但默认设置应该可以正常工作。
启动并启用php-fpm.service. 重新启动 httpd.service。
3.4.2 测试PHP是否有效
要测试 PHP 是否已正确配置,请在您的 ApacheDocumentRoot目录(例如/srv/http/或~<username>/public_html/)中创建一个文件test.php,其中包含以下内容:
<?php phpinfo();
然后根据需要转到http://localhost/test.php或 http://localhost/~<username>/test.php
http://127.0.0.1/~tom/
http://127.0.0.1/~tom/test.php
http-server相关推荐
- 【Sql Server】数据库的3大服务
在数据库SQL SERVER中,处理常用的sql server数据库引擎,还有其他3大服务,分别是集成服务,报表服务,分析服务. 集成服务商可以配置包,这里的包可以理解是数据库引擎里的用户数据库.可以 ...
- 【Sql Server】DateBase-自动化
强大的SQL Server有着神奇的自动化功能,来处理一些人为处理不了的事情! 自动化功能:T-sql语言,系统命令.脚本语言.复制命令.创建角色.索引重建.报表 管理元素:作业.警报.操作员.计划 ...
- 【Sql Server】DateBase-触发器
触发器是数据库中一种特殊的对象,当使用触发器时,一旦执行某个操作,就会触发执行的一段代码! 语法: Create trigger 名 On[table|view] { For after instea ...
- 【Sql Server】DateBase-视频总结
最近看完了数据库视频,内容繁杂,但也不是无迹可寻! 这是第三遍关于数据库的学习了,随着一遍一遍的深入,更加了解了它的全貌,虽然现在对于数据库还不能到达熟练操作的地步,但至少放我手上不在犯怵了. SQL ...
- sql server登录名、服务器角色、数据库用户、数据库角色、架构区别联系
原创链接:https://www.cnblogs.com/lxf1117/p/6762315.html sql server登录名.服务器角色.数据库用户.数据库角色.架构区别联系 1.一个数据库用户 ...
- 分布式TensorFlow集群local server使用详解
通过local server理解分布式TensorFlow集群的应用与实现. 简介 TensorFlow从0.8版本开始,支持分布式集群,并且自带了local server方便测试. Local ...
- 合肥工业大学—SQL Server数据库实验十:用户及其权限管理
用户及其权限管理 1. 创建登录名Mylog及密码 2. 创建用户user2关联登录名 3. 创建角色role1 4. 对用户user2及角色role1授权 5. 验证用户授权 6. 收回用户权限 1 ...
- 合肥工业大学—SQL Server数据库实验四:数据库的分离和附加
数据库的分离和附加 1. 数据库分离 2. 数据库附加 1. 数据库分离 当SQL Server服务器运行时,该服务器上所有的数据库自动处于运行状态,而运行中的数据库文件是无法进行数据库文件的拷贝的. ...
- 用户自定义协议client/server代码示例
用户自定义协议client/server代码示例 代码参考链接:https://github.com/sogou/workflow message.h message.cc server.cc cli ...
- mysql navicat导入bcp_SQL Server中BCP导入导出用法详解
bcp命令是SQL Server提供的一个快捷的数据导入导出工具.使用它不需要启动任何图形管理工具就能以高效的方式导入导出数据.bcp是SQL Server中负责导入导出数据的一个命令行工具,它是基于 ...
最新文章
- 关于安防与大数据不能不说的九个发展趋势
- ArcGIS for JavaScript 关于路径开发的一些记录(二)
- 拼图游戏_我最喜欢的Java拼图2 + 1 = 4
- shopex还是ecshop
- C实现的一个简单的学生成绩管理系统
- python中双冒号_c++中冒号(:)和双冒号(::)的用法和c/c++ 位域结构体
- 在Git中更改文件名的大小写
- oracle技术之浅述当前模式读与一致性读
- 可视化实验二:大数据可视化工具—Tableau
- python自动化开发-[第九天]-异常处理、进程
- 5oSf6KeJ5Lul5ZCO5Y+v5Lul55SoYmFzZTY05Yqg5a+G6ZqP56yU
- win10开始菜单 此计算机,详细教您win10开始菜单打不开怎么办
- JSAPI支付——H5网页端调起支付接口
- 【转】3xian之所在
- 《RefineMask:Towards High-Quality Instance Segmentation with Fine-Grained Features》论文笔记
- 我决定辞掉工作,全职开发我的操作系统!(续)
- AT89C51单片机交通灯仿真图+代码
- 使用vite创建单页应用
- 学习设计模式应该读哪些书
- 【无标题】Android studio连接第三方模拟器全解
热门文章
- mysql unknown option_在cmd下输入mysql: [ERROR] unknown option '-- '.是什么意思啊,求解
- 如何替换json对象中的key
- QMI8658 - 姿态传感器学习笔记 - Ⅲ
- Win10中找不到gpedit.msc
- GD图片处理——缩放、剪切、相框、水印、锐化、旋转、翻转、透明度、反色
- GloVe 词向量模型
- UDF UDAF UDTF 区别
- Mybatis最入门---分页查询(逻辑分页与SQL语句分页)
- 排序与分页Pagination
- MySQL 10060错误 解决方法