Apache 和 Nginx 安装介绍

Apache 安装和使用
Apache 可以在 macOS、Linux 和 Windows 等操作系统上安装使用。这里以 macOS 为例:

  1. 使用 Homebrew 安装:
    brew install httpd
  2. 修改配置文件:
    vim /usr/local/etc/httpd/httpd.conf
    找到 DirectoryIndex 选项,取消注释并修改为:
    DirectoryIndex index.html
  3. 启动Apache:
    httpd
    或在后台运行:
    brew services start httpd
  4. 在网站根目录下创建 index.html 文件,然后可以访问 http://localhost 看到测试页面。
  5. 停止Apache: Ctrl + C 或运行 brew services stop httpd。

Nginx 安装和使用
Nginx 也可以运行在多操作系统上,这里同样以 macOS 为例:

  1. 使用 Homebrew 安装:
    brew install nginx
  2. 修改配置文件:
    vim /usr/local/etc/nginx/nginx.conf
    找到 server 块,修改 root 指向网站根目录:
    server {
    listen 80;
    root /path/to/website;
    }
  3. 启动Nginx:
    nginx
    或在后台运行:
    brew services start nginx
  4. 在网站根目录下创建 index.html 文件,然后可以访问 http://localhost 看到测试页面。
  5. 停止Nginx:
    运行 nginx -s stop 或 brew services stop nginx。
    Apache 和 Nginx 都是强大稳定的 Web 服务器,在实际使用过程中,可以根据需求选择使用其中一个或同时使用。

脚本安装nginx:

#!/bin/bash
cd /usr/local/src
yum install wget vim unzip pcre pcre-devel gcc* -y
yum install openssl openssl-devel -y
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar xf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
./configure --prefix=/data/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module
make && make install
#mkdir /data/app/nginx -p
#ln -s /application/nginx-1.18.0/ /application/nginx
echo 'export PATH=/data/app/nginx/sbin:$PATH' >>/etc/profile
source /etc/profile
cd /data/app/nginx/conf
mkdir conf.d ssl
nginx -t
netstat -lntup|grep nginx

在主配置文件中,include 所有的虚拟主机配置:

include  /data/app/nginx/conf/conf.d/*.conf;
include  /data/app/nginx/conf/conf.d/*/*.conf;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是可以的。您可以通过在CentOS 8上安装ApacheNginx来实现此目的。首先,确保您的系统已启用EPEL存储库。然后,按照以下步骤进行操作: 1. 安装ApacheNginx 使用以下命令安装ApacheNginx: ``` sudo dnf install httpd nginx ``` 2. 配置Apache 默认情况下,Apache监听端口80。您可以通过编辑`/etc/httpd/conf/httpd.conf`文件来更改Apache的默认设置。找到以下行: ``` Listen 80 ``` 将其更改为: ``` Listen 127.0.0.1:8080 ``` 这将使Apache仅在本地侦听端口8080。 3. 配置Nginx 默认情况下,Nginx监听端口80。您可以通过编辑`/etc/nginx/nginx.conf`文件来更改Nginx的默认设置。找到以下行: ``` listen 80 default_server; ``` 将其更改为: ``` listen 127.0.0.1:8081 default_server; ``` 这将使Nginx仅在本地侦听端口8081。 4. 配置虚拟主机 现在,您需要为ApacheNginx分别配置虚拟主机。在Apache中,您可以通过编辑`/etc/httpd/conf.d/vhosts.conf`文件来添加虚拟主机。例如: ``` <VirtualHost *:8080> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/apache ServerName apache.example.com ErrorLog logs/apache-error.log CustomLog logs/apache-access.log combined </VirtualHost> ``` 在Nginx中,您可以通过编辑`/etc/nginx/conf.d/vhosts.conf`文件来添加虚拟主机。例如: ``` server { listen 127.0.0.1:8081; server_name nginx.example.com; location / { root /var/www/html/nginx; index index.html; } } ``` 5. 启动ApacheNginx 使用以下命令启动ApacheNginx: ``` sudo systemctl start httpd sudo systemctl start nginx ``` 现在,您可以通过访问`http://127.0.0.1:8080`来访问Apache,并通过访问`http://127.0.0.1:8081`来访问Nginx

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值