sho*_*key 3 server firefox apache2 nginx
我已经安装了 apache2 和 nginx 作为网络服务器。
我发现很奇怪,apache2的标志在service apache2 stop执行时仍然会在firefox中显示,而nginx标志在执行时无法在firefox中显示service nginx start。

无论您停止 apache2 还是启动 nginx,apache2 debian 默认页面始终显示在我的 Firefox 中。
apache2的配置文件/etc/apache2/sites-available/000-default.conf如下:
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
nginx 的配置文件 /etc/nginx/sites-available/default 如下:
server {
listen 8080;
server_name 127.0.0.1;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的操作系统中,
ls /var/www/html
index.nginx-debian.html index.html
Run Code Online (Sandbox Code Playgroud)
index.html 是一个 apache2 debian logo,每次 127.0.0.1:8080 执行,index.html 都会被调用,无论是 apache2 还是 nginx 都会显示 apache2 debian logo。
问题解决了。
小智 6
这里真的有两个问题,所以我会尽量回答它们:
1. 为什么Apache和Nginx显示的是同一个网页?
仔细查看您的配置文件。您将看到它们都加载了相同的内容:
Apache 正在加载(文档根目录):/var/www/html
Nginx 正在加载(根):/var/www/html;
这意味着两个服务器将显示相同的内容,因为它们正在加载相同的文件。您可以通过编辑配置文件将“根”目录更改为两个不同的位置。
例如阿帕奇:
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/apache
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
例如nginx:
server {
listen 8080;
server_name 127.0.0.1;
root /var/www/html/nginx;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html/nginx;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您需要创建每个目录并在其中放置一个文件:
mkdir /var/www/html/nginx
mkdir /var/www/html/apache
Run Code Online (Sandbox Code Playgroud)
并将内容放入每个文件夹中。还值得检查每个文件夹的权限是否适合 Web 服务器访问它们。
2.如何查看Apache是否已停止,Nginx是否已启动
有一种简单的方法可以检查每个服务的状态。假设您以 root 身份登录:
service apache2 stop #Stop apache
service apache2 status #is apache still running?
Run Code Online (Sandbox Code Playgroud)
也可以使用 ps 命令获取进程列表:
ps aux | grep -i apache
Run Code Online (Sandbox Code Playgroud)
这有效地获取所有正在运行的进程,并搜索任何名称为 apache 的进程。
然后,您可以启动 nginx 并检查它是否正在运行:
service nginx start #start nginx
service nginx status #is nginx running?
Run Code Online (Sandbox Code Playgroud)
(可选的另一种证明进程正在运行的方法): ps aux | grep -i nginx
还可以查看哪个程序正在侦听哪个端口:
netstat -ntlp
Run Code Online (Sandbox Code Playgroud)
这将告诉您本地地址、端口和进程名称,用于侦听计算机上的连接。您应该在此列表中看到 nginx 或 apache 运行时暴露了端口 8080(基于您的配置文件)。
| 归档时间: |
|
| 查看次数: |
12709 次 |
| 最近记录: |