简体   繁体   English

如何使用apache2运行我的HTML文件

[英]How to run my html file with apache2

Maybe it is not a right channel to ask this question but I donot know where to ask. 也许这不是问这个问题的正确渠道,但我不知道在哪里问。

I want to know how to run html file with apache on my ubuntu. 我想知道如何在我的Ubuntu上用apache运行html文件。 I have written program with javascript and a html file and I want to run it via apache. 我已经用javascript和html文件编写了程序,我想通过apache运行它。 I could not find htdocs folder in to copy my files there beside that I do not have permission to do that in ubuntu. 我找不到htdocs文件夹来复制我的文件,此外我没有权限在ubuntu中这样做。 My apache is installed in /usr/share/apache2. 我的apache安装在/ usr / share / apache2中。 When I write http://localhost it says: 当我写http://localhost时说:

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

but I do not know where to add the contents. 但我不知道在哪里添加内容。

any help. 任何帮助。

The default folder that it serves the HTML files from is /var/www . 提供HTML文件的默认文件夹是/var/www

For example, /var/www/test.html would be http://localhost/test.html . 例如, /var/www/test.html将是http://localhost/test.html

In my case where I have installed and running the Apache 2 and if I type localhost/ into the browser it opens the Apache 2 Ubuntu default Page. 在我已经安装并运行Apache 2的情况下,如果我在浏览器中键入localhost/ ,它将打开Apache 2 Ubuntu默认页面。

Now what I did was: Suppose your HTML webpage Demo.html is located in the Website directory then copy the HTML page using one of the commands: 现在我要做的是:假设您的HTML网页Demo.html位于Website目录中,然后使用以下命令之一复制HTML页面:

:~$ cp ~/Website/Demo.html /var/www/html

If this command does not work then try with the following command: 如果此命令不起作用,请尝试以下命令:

:~$ sudo cp ~/Website/Demo.html /var/www/html

And then open your browser and type this the browser search bar: localhost/Demo.html 然后打开浏览器并在浏览器搜索栏中键入以下内容:localhost / Demo.html

It will open the copied Demo.html. 它将打开复制的Demo.html。

Also if you want to access this hosted webpage from the outside of the machine where Apache 2 is running then use it's external IP address instead of localhost as follows: 另外,如果要从运行Apache 2的计算机外部访问此托管网页,请使用其外部IP地址代替localhost,如下所示:

ExternalIP/Demo.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM