Running the Python HTTP Server
Once you have verified that Python is installed and the http.server
module is available, you can start the Python HTTP server to serve files over the network.
Starting the HTTP Server
To start the Python HTTP server, open a terminal or command prompt on your Ubuntu 22.04 system and run the following command:
python -m http.server
This will start the HTTP server on the default port 8000. You can then access the server by opening a web browser and navigating to http://localhost:8000
.
sequenceDiagram
participant Client
participant Server
Client->>Server: HTTP Request
Server->>Client: HTTP Response
Customizing the Server Settings
You can customize the behavior of the Python HTTP server by passing additional arguments to the python -m http.server
command. Some common options include:
--bind/-b
: Specify the address to bind the server to (default is 0.0.0.0
)
-p/--port
: Specify the port to use (default is 8000)
-d/--directory
: Specify the directory to serve files from (default is the current directory)
For example, to start the server on port 8080 and serve files from the /var/www/html
directory, you can use the following command:
python -m http.server --port 8080 --directory /var/www/html
Accessing the Server
Once the server is running, you can access it from any device on the same network by navigating to the server's IP address and port in a web browser. For example, if the server is running on a machine with the IP address 192.168.1.100
, you can access the server by going to http://192.168.1.100:8000
.
By following these steps, you can easily start and customize the Python HTTP server to serve files over the network.