Apache
Apache基本操作
- 安裝 yum install httpd(centos)
- 啟動 service httpd start
- 停止 service httpd stop
注意防火墻(firewalld)
(操作演示:)
捕獲.PNG
(訪問服務器80端口)
80_test.PNG
Apache的虛擬主機配置和偽靜態(tài)操作
虛擬主機配置
- 編輯配置文件/etc/httpd/conf/httpd.conf
cd /etc/httpd/conf/httpd.conf
vim httpd.conf
# virtual host being defined.
#
<VirtualHost *:80>
ServerName www.fxqp1202.com
DocumentRoot /data/www
<Directory>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
#
- 重啟httpd服務
service httpd restart - 創(chuàng)建DocumentRoot
mkdir -p /data/www - 將目錄所有者設置為其它非root用戶
sudo chown -R(遞歸) alice:alice /data -
指定域名所對應的服務器
vim /etc/hosts
(如果是公網(wǎng),需要將自己購買的域名先解析到自己的服務器,這樣設置一下字段是才會有用,否則公網(wǎng)DNS查詢時,查詢不到ip。)
39.98.164.240 www.fxqp1202.com
39.98.164.240 www.fxqp1202.xin
(通過域名來區(qū)分不同的虛機)
(阿里云解析DNS需要實名認證,否則會產生異常。)
臨時設置強制和寬松模式( SELinux)
setenforce 1(強制模式)
setenforce 0(寬松模式)
直接SELinux設置
vim /etc/selinux/config
SELINUX=disabled
偽靜態(tài)操作
(比如php寫的文件,訪問的時候應該是php結尾,但是,使用偽靜態(tài),可以以html結尾,有利于SEO優(yōu)化。)
- 查看一下偽靜態(tài)相關的module文件
cd /etc/httpd/modules
與偽靜態(tài)相關的module文件:mod_rewrite.so
- 配置文件中加載偽靜態(tài)模塊
vim /etc/httpd/conf/httpd.conf
/LoadModule(查找到相應的位置)
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule rewrite_module modules/mod_rewrite.so
- 設置具體的偽靜態(tài)規(guī)則
<VirtualHost *:80>
ServerName www.fxqp1202.com
DocumentRoot /data/www
<Directory>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
<IfModule mod_rewrite.c>
RewriteEngine on
RewrireRule ^(.*).htmp$ index.html
<IfModule>
</Directory>
</VirtualHost>
- 重啟httpd
- (所有的.htmp文件都會重定向到index.html)
- 訪問
Nginx
nginx的基本操作
- 安裝
- 添加Centos7 Nginx yum資源庫
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm- 安裝
sudo yum install -y nginx - 啟動
service nginx start
[root@fxqp1202 ~]# service nginx start
Redirecting to /bin/systemctl start nginx.service
[root@fxqp1202 ~]# ps -ef | grep nginx
root 3402 1 0 21:19 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 3403 3402 0 21:19 ? 00:00:00 nginx: worker process
root 3405 3232 0 21:19 pts/0 00:00:00 grep --color=auto nginx
[root@fxqp1202 ~]#
啟動.PNG
- 停止(stop)
- 重啟(restart)
- 重載
(nginx服務器重啟過程中,用戶無法訪問。)
(而重載是無縫遷移。)
service nginx reload
- 查看配置文件
[root@fxqp1202 ~] cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
- 看看根目錄
(cat /usr/share/nginx/html/index.html)
(這個就是歡迎頁面的內容?。?/li>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
虛擬主機配置
- 首先復制一份配置文件
(cp default.conf fxqp1202.conf)
server {
listen 80;
# listen 8000;(可以監(jiān)聽多個端口)
server_name www.fxqp1202.com;
# server_name www.fxqp1202.com www.imooc.test;(多域名)
# 域名需要設置DNS解析,(Host文件)
location / {
root /data/www;
index index.html index.htm;
}
}
- 重載
- 訪問