Mac 10.9.x already comes with Apache, which can be enabled as follows:
1. Start
Sudo apachectl start
After the startup, access http: // localhost/and you will be able to see "It works! "If you are curious about the content of the initial Page, open"/etc/apache2/httpd. conf "and see the following code snippet in line 197:
1 <Directory "/Library/WebServer/Documents"> 2 # 3 # Possible values for the Options directive are "None", "All", 4 # or any combination of: 5 # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 6 # 7 # Note that "MultiViews" must be named *explicitly* --- "Options All" 8 # doesn‘t give it to you. 9 #10 # The Options directive is both complicated and important. Please see11 # http://httpd.apache.org/docs/2.2/mod/core.html#options12 # for more information.13 #14 Options Indexes FollowSymLinks MultiViews15 16 #17 # AllowOverride controls what directives may be placed in .htaccess files.18 # It can be "All", "None", or any combination of the keywords:19 # Options FileInfo AuthConfig Limit20 #21 AllowOverride None22 23 #24 # Controls who can get stuff from this server.25 #26 Order allow,deny27 Allow from all28 29 </Directory>
View code
The content of it works is in the/library/webserver/documents/index.html. En file. This is an Apache Development page, which is equivalent to the IIS c: \ Inetpub \ wwwroot \ iisstart.htm in windows.
2. Restart/stop
Sudo apachectl restart
Sudo apachectl stop
3. Create a personal site directory
Cd ~ /
Mkdir sites
Echo "hello"> index.html
Sudo apachectl restart
Then access http: // localhost /~ Jimmy/should be able to see the "hello" personal directory initial Page (note:~ JimmyChange~ Your username)
If it fails, check whether the name is Jimmy in the "/etc/apache2/users" directory. conf "configuration file (similarly: Jimmy needs to change to your user name). If not, create one manually. For details, refer to the following:
1 <Directory "/Users/jimmy/Sites/">2 Options FollowSymLinks Indexes MultiViews3 AllowOverride All4 Order allow,deny5 Allow from all6 </Directory>
View code
If you are curious about why the directory name is sites? View "/etc/apache2/extra/httpd-userdir.conf"
1 # Settings for user home directories 2 # 3 # Required module: mod_userdir 4 5 # 6 # UserDir: The name of the directory that is appended onto a user‘s home 7 # directory if a ~user request is received. Note that you must also set 8 # the default access control for these directories, as in the example below. 9 #10 UserDir Sites11 12 #13 # Users might not be in /Users/*/Sites, so use user-specific config files.14 #15 Include /private/etc/apache2/users/*.conf16 <IfModule bonjour_module>17 RegisterUserSite customized-users18 </IfModule>
View code
Row 3 is the answer
4. Enable VM
By default, Apache's Vm function is disabled. Find the following line in "/etc/apache2/httpd. conf:
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Remove the previous #, and then open "/etc/apache2/extra/httpd-vhosts.conf", the content is modified to look like the following:
1 NameVirtualHost *:80 2 3 <VirtualHost *:80> 4 DocumentRoot "/Users/jimmy/Sites" 5 ServerName www.yjmyzz.com 6 ErrorLog "/Users/jimmy/Sites/log/error.log" 7 CustomLog "/Users/jimmy/Sites/log/access.log" common 8 <Directory /> 9 Options Indexes FollowSymLinks MultiViews10 AllowOverride None11 Order deny,allow12 Allow from all13 </Directory>14 </VirtualHost>
View code
Note:
A) The/users/Jimmy/sites/log file directory must exist. Otherwise, Apache startup will fail and no error message will be prompted.
B) The site root directory of the VM, which is recommended to be placed in ~ /Sites/. Otherwise, an error similar to "no access permission" will be reported in the Mac environment.
This configuration is bound to a nonexistent domain name www.yjmyzz.com to the site http: // localhost /~ Jimmy/, manually modify the hosts file to verify the effect of domain name binding
Sudo VI/etc/hosts open the hosts file as an administrator and append a line
127.0.0.1 www.yjmyzz.com
Save and exit, restart Apache, browse http://www.yjmyzz.com again should be OK, see the content with http: // localhost /~ Jimmy/same
5. url forwarding
Open httpd. conf first to make sure the following two lines are not commented out:
1 LoadModule proxy_module libexec/apache2/mod_proxy.so2 LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
Add
1 ProxyPass /HelloApp http://localhost:8080/HelloApp/2 ProxyPassReverse /HelloApp http://localhost:8080/HelloApp/
Access http: // localhost/helloapp, http: // ip/helloapp, http://www.yjmyzz.com/HellpApp are equivalent to access http: // localhost: 8080/helloapp