Use Raspberry Pi to build your own web server (2) set up Apache

Source: Internet
Author: User

Use Raspberry Pi to build your own web server (2) set up Apache
1. get Server IP Address: ifconfig2. change the local hosts file. If you want to enter a domain name in your browser, you can also access your server. You need to change the hosts file in your computer in linux: sudo vim/etc/hostswindows: C: \ Windows \ System32 \ drivers \ etc \ hosts open the host file and add the following content:. you Rname.com or www.myname.com can directly access the website on your server. You can use ping www.yourname.com to test 3. create a website directory file. Next we need to create the root directory and test page of the two websites under the apache root directory, so that we can enter the specified connection to access our different pages 1 sudo mkdir {/var/www/yourname.com,/var/www/myname.com} and then create the pages respectively, write sudo vim/var/www/yourname.com/index.htmlsudo vim/var/www/myname.com/index.html 4. if you access yourname.com and myname.com in your browser at this time, you will find that the original it works page is still opened, the two indexes created for different domain names are not accessed correctly. h To access different domain names on the tml page, we still need to take the last step, the most important step is to set the apache Virtual Host Configuration File of apache Virtual Host in/etc/apache2/sites-available/. For details, refer to the 000-default.conf file in this directory, create a new vhosts. conf file, sudo vim/etc/apache2/sites-available/vhosts. enter the following content in the conf file: -------------------------------------------------- <VirtualHost *: 80> ServerName www.yourname.com ServerAlias yourname.com DocumentRoot/var/www/yourname.com </VirtualHost> <VirtualHost *: 80> ServerName www.myname.com ServerAlias myname.com DocumentRoot/var/www/myname.com </VirtualHost> ---------------------------------------------------- each <VirtualHost>... </VirtualHost> the tag specifies a virtual host. The host domain name is the domain name after ServerName, and the root directory of the host is the directory entered after DocumentRoot. ServerAlias is the alias of the website domain name. The link after accessing it is equivalent to the link after directly accessing ServerName. Finally, we need to set the created vhost. create a soft connection in the conf file and put it in the/etc/apache2/sites-enabled/directory sudo ln-s/etc/apache2/sites-available/vhosts. conf/etc/apache2/sites-enabled/5. after the test, all the settings are complete. Enter the corresponding website in the browser to open the website page in different directories. By the way, each time the configuration file is modified, restart apache to re-read the new settings. Otherwise, all the settings just made will be ignored. Sudo service apache2 restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.