<?php echo 123; ?> php
curl localhost/test.phphtml
要想實現php的效果先編輯Apache測試文件!linux
[root@Dasoncheng ~]# vim /usr/local/apache2.4/conf/httpd.conf …… ServerName www.app.com …… <Directory /> AllowOverride none Require all granted </Directory> …… AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php …… <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> ……
這裏插入Linux防火牆知識:
selinux //臨時關閉 setenforce 0
selinux //永久關閉 vi /etc/selinux/config
centos7以前使用netfilter防火牆、
centos7開始使用firewalld防火牆
關閉firewalld開啓netfilter方法:
systemctl stop firewalld
systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables
systemctl start iptablesweb
##關於selinux: ##臨時關閉: [root@Dasoncheng ~]# getenforce Enforcing [root@Dasoncheng ~]# setenforce 0 [root@Dasoncheng ~]# getenforce Permissive ##永久關閉: [root@Dasoncheng ~]# vim /etc/selinux/config [root@Dasoncheng ~]# grep -B2 -w '^SELINUX' /etc/selinux/config # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled
##關於關閉firewalld開啓netfilter: [root@Dasoncheng ~]# systemctl stop firewalld [root@Dasoncheng ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. [root@Dasoncheng ~]# yum install -y iptables-services [root@Dasoncheng ~]# systemctl enable iptables.service Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service. [root@Dasoncheng ~]# systemctl start iptables.service [root@Dasoncheng ~]# iptables -F [root@Dasoncheng ~]# iptables -nvL Chain INPUT (policy ACCEPT 6 packets, 428 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 4 packets, 448 bytes) pkts bytes target prot opt in out source destination [root@Dasoncheng ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
編輯好了httpd.conf以後,測試:apache
[root@Dasoncheng ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK [root@Dasoncheng ~]# /usr/local/apache2.4/bin/apachectl graceful [root@Dasoncheng ~]# ps aux |grep httpd daemon 22383 0.1 0.9 540344 9520 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 22384 0.1 0.9 540344 9512 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 22386 0.1 0.9 540344 9508 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start root 22468 0.0 0.0 112664 968 pts/0 S+ 10:13 0:00 grep --color=auto httpd root 34165 0.0 1.2 253516 12792 ? Ss 03:56 0:02 /usr/local/apache2.4/bin/httpd -k start [root@Dasoncheng ~]# netstat -lntp |grep httpd tcp6 0 0 :::80 :::* LISTEN 22383/httpd [root@Dasoncheng ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
若是沒法訪問,從selinux、防火牆、端口等進行排查!vim
[root@Dasoncheng ~]# curl localhost <html><body><h1>It works!</h1></body></html>
先編輯wins的hosts文件:
域名訪問:
centos
[root@Dasoncheng ~]# vim /usr/local/apache2.4/conf/httpd.conf ##編輯主配置文件,開啓虛擬主機(開啓以後,原站點就會失效!) [root@Dasoncheng ~]# grep -A1 'Virtual hosts' /usr/local/apache2.4/conf/httpd.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf
[root@Dasoncheng ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com 123.com ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common </VirtualHost> <VirtualHost *:80> # ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/data/wwwroot/111.com" ServerName www.111.com ErrorLog "logs/111.com-error_log" CustomLog "logs/111.com-access_log" common </VirtualHost>
[root@Dasoncheng ~]# mkdir -p /data/wwwroot/abc.com/ [root@Dasoncheng ~]# cat /data/wwwroot/abc.com/index.php <?php echo "abc.com"; ?> [root@Dasoncheng ~]# mkdir -p /data/wwwroot/111.com [root@Dasoncheng ~]# cat /data/wwwroot/111.com/index.php <?php echo "111.com"; ?>
小提示:開啓了虛擬主機以後,原先的主配置站點就失效!
虛擬主機配置文件能夠定義多個virtual host;每個host表明一個站點!其中第一個host就變爲了主站點,訪問ip就是這個主機!app
[root@Dasoncheng ~]# curl -x192.168.60.11:80 www.abc.com abc.com ##ServerAlias我就沒有測試,下面也沒有; [root@Dasoncheng ~]# curl -x192.168.60.11:80 www.111.com 111.com [root@Dasoncheng ~]# vim /etc/hosts [root@Dasoncheng ~]# tail -1 /etc/hosts 192.168.60.11 www.abc.com www.111.com [root@Dasoncheng ~]# curl www.abc.com abc.com [root@Dasoncheng ~]# curl www.111.com 111.com [root@Dasoncheng ~]# curl http://192.168.60.11 abc.com
apache全部的主機都指向第一個? http://www.aminglinux.com/bbs/thread-491-1-1.htmlcurl