关于virtual host的问题
Testing locally like this is great. What I do in addition is to set up a virtual host so I can use a web address instead of IP. I name my sites with a ‘.dev’ domain so they’re not confused with and I can still reach out to live sites.
Local testing:
http://www.google.dev
I hope these instructions will be of value to others.
Open BBEdit or TextWrangler (a free, cut-down version of BBEdit available fromwww.barebones.com). From the File menu, select Open Hidden. In the Open dialog box, select All Files from the Enable drop-down menu. Then navigate to Macintosh HD:private:etc:hosts
, and click Open.
This opens a system file, so you need to unlock it by clicking the icon of a pencil with a line through it at the top-left of the toolbar, as shown in the following screenshot:
You will be told that the document is owned by "root", and be asked to confirm that you want to unlock it. Click Unlock. This removes the line through the pencil, and readies the file for editing.
Place your cursor on a new line at the end of the file, and type 127.0.0.1 followed by a space and the name of the virtual host you want to create. If you're following the examples in The Essential Guide to Dreamweaver CS3, it should look like this:
Save the file. Because it's owned by "root", you will be prompted to enter your Mac password. That takes care of the changes that used to be made in NetInfo Manager. You now need to tell Apache about the virtual host.
Use BBEdit or TextWrangler to open the main Apache configuration file, httpd.conf
. It's a system file, so you need to open and unlock it in the same way as the hosts
file. It's located at Macintosh HD:private:etc:apache2:httpd.conf
.
Scroll down to around line 460 and locate the following lines:
# Virtual hosts#Include /private/etc/apache2/extra/httpd-vhosts.conf
Remove the hash (pound) sign from the beginning of the second of these two lines like this:
Include /private/etc/apache2/extra/httpd-vhosts.conf
This enables the configuration file for virtual hosts, which now needs to be edited.
Use BBEdit or TextWrangler to open httpd-vhosts.conf
. Again, it's a system file, so needs to be handled the same way as the previous two files. The file is located at Macintosh HD:private:etc:apache2:extra:httpd-vhosts.conf
.
The section of the file that you're interested in is shown in the following screenshot:
Lines 27–42 of the preceding screenshot are examples of virtual host definitions. You need to replace these with your own definitions. When you enable virtual hosting, Apache disables the main server root, so the first definition needs to reproduce it.
You don't need all the options shown in the examples, so replace the code shown on lines 27–42 of the preceding screenshot with the following:
<VirtualHost *:80> DocumentRoot "/Library/WebServer/Documents" ServerName localhost
</VirtualHost><VirtualHost *:80> DocumentRoot "/Users/username/Sites/egdwcs3" ServerName egdwcs3</VirtualHost>
Replace "username" in the second definition with your own Mac username.
Save all the files you have edited, and restart Apache by going to Sharing in System Preferences, deselecting Web Sharing, and selecting it again. You should now be able to access the virtual host with the following URL: http://egdwcs3/
.
HTML Editor: BBEdit 8
BBEdit is the holy grail of text editors for the Macintosh. It includes built in validation, preview in any browser, auto indenting, and HTMLTidy. HTMLTidy is a great tool for ensuring your HTML is valid. If you forget to close a tag, Tidy will take care of it for you.
Honorable Mentions
BBEdit carries a steep price of $179, but if you spend most of your day working on HTML, it is well worth the investment.
CSS Editor: CSSEdit
Sure I could use BBEdit to write my CSS, but why would I want to when CSSEdit makes it easy for me to manipulate my styles? CSSEdit gives you the choice of a friendly Aqua interface to input commonly used CSS attributes for text, padding, borders, and backgrounds or a powerful manually entry mode. If you decide to type out your own CSS in manual mode, CSSEdit lends a helping hand with its auto-complete functionality. Less typing is a good thing.
CSSEdit is worth $24.95, and I recommend it to anyone that is serious about designing web pages. I don't know how I lived without it.