Apache的使用和配置

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值