1.相关指令
Apache(麒麟系统)
systemctl status httpd 查看状态
systemctl start httpd 启动
systemctl stop httpd 停止
systemctl restart httpd 重启
systemctl enable httpd 开机启动
systemctl disable httpd 开机关闭
Apache2相关:
httpd -k start
httpd -k restart
httpd -k stop
2.相关位置
配置文件:
/etc/httpd/conf/httpd.conf(find / -name httpd.conf )
程序:
/usr/sbin/apachectl (find / -name apachectl)
日志:
/var/log/httpd/error_log
3.apache配置文件httpd.conf简述
1)#为注释
- ServerRoot: The top of the directory tree under which the server’s configuration, error, and log files are kept.
这里配置的各种配置文件的位置,
ServerRoot "/etc/httpd"
Listen: Allows you to bind Apache to specific IP addresses and/or ports, instead of the default. See also the
Listen 监听的端口或者固定的IP
Listen 80
Listen 8080
Listen 5000
Listen 8888
Listen 12.34.56.78:80
注意:如果用Apache监听这些端口,其他应用再通过这个端口工作就会冲突
- LoadModule foo_module modules/mod_foo.so
- 加载模块,指定的是模块名字和相对的模块位置
在这里我加入了模块:
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi_python3.so
- DocumentRoot “/var/www/html”
指定根目录
最后的这句话非常重要,指定了在serverRoot指定目录的相对目录conf.d下的所有.conf文件都是配置文件,比如可以用于配置虚拟主机,在启动Apache时会启动这些配置文件
IncludeOptional conf.d/*.conf
4.配置虚拟主机示例
因为在conf目录下的*.conf都可以执行,所以在这个目录下可以定义虚拟主机。不过虚拟主机的文件名需要是 xxx.conf
<virtualhost 192.168.8.124:5000>
ServerName 192.168.8.124
DocumentRoot "/aips/aips-nxp-web-back/app"
WSGIDaemonProcess app threads=5 python-home=/aips/aips-nxp-web-back/venv python-path=/aips/aips-nxp-web-back/venv/lib/python3.7/site-packages
WSGIScriptAlias / /aips/aips-nxp-web-back/app/app.wsgi
<directory /aips/aips-nxp-web-back/app>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</virtualhost>
例子2:
<virtualhost *:80>
ServerName app.seesaw.top
WSGIDaemonProcess app threads=5 python-path=/var/www/app/env/lib/python3.6/site-packages
WSGIScriptAlias / /var/www/app/app.wsgi
<directory /var/www/app>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
ErrorLog ${APACHE_LOG_DIR}/app.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/app.access.log combined
</virtualhost>
这里配置了虚拟主机的IP和指定端口号,指定了该虚拟主机的根目录等,也进行了wsgi配置
相关解释:
<VirtualHost *:80>
ServerName localhost
# 指定根目录
DocumentRoot /data/www/project/
//根目录是谁的根目录?
# WSGIDaemonProcess用于指定应创建不同的守护进程,设置守护进程组的名称为 wsgi_api
# threads 指定线程数为5
# python-home 指定守护进程使用的 Python 虚拟环境的位置为/data/www/project/venv
# python-path 引用 Python 虚拟环境的 site-packages 目录
WSGIDaemonProcess wsgi_api threads=5 python-home=/data/www/project/venv python-path=/data/www/project/venv/lib/python3.6/site-packages
# WSGIScriptAlias 与 Alias 指令相同,将特定文件路径 /api 标记为脚本 /data/www/project/api/app.wsgi,此脚本应由mod_wsgi 的 wsgi-script 处理程序处理
WSGIScriptAlias /api /data/www/project/api/app.wsgi
<Directory /data/www/project/api>
WSGIProcessGroup wsgi_api
WSGIApplicationGroup %{GLOBAL}
# WSGIScriptReloading 设置对WSGI脚本文件的更改都触发重新加载机制
WSGIScriptReloading On
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
5. 前端配置允许局域网内访问示例
5.1 Ubuntu 安装Apache2
sudo apt-get install apache2
5.2 配置启动Apache2
配置文件位置:
/etc/apache2/apache2.conf
5.3 配置apache.conf 和虚拟主机
配置虚拟主机 位置:/conf-enable/front.conf
<virtualhost 192.168.8.158:8080>
ServerName 192.168.8.158
DocumentRoot "/var/www"
ErrorLog /var/www/front_error.log
<directory /var/www>
Options FollowSymLinks
AllowOverride all
Require all granted
Order deny,allow
Allow from all
</directory>
</virtualhost>
配置文件apache.conf内容:
ServerRoot "/etc/apache2"
Listen 8080
ServerName 192.168.8.158:8080
Include ports.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
Order Deny,Allow
Allow from all
</Directory>
<FilesMatch "^\.ht">
Require all granted
</FilesMatch>
5.4 其他注意事项
记得不要开防火墙,如果需要某个口外接就要把那个口放开,如果不会就直接通过
systemctl stop firewalld