DevOps Lesson
import socket
# Change the following host and see what IP it prints!
host = "youtube.com"
ip = socket.gethostbyname(host)
print(ip)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
print("Successfully connected!")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
# Send a GET request to "/"
s.sendall(b"GET / HTTP/1.1\r\n\r\n")
# Recieve & print 2048 bytes of data
data = s.recv(2048)
print(data.decode())
import requests
# Change the URL to whatever you'd like
response = requests.get("https://google.com")
print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])
# Add a line to print the "Content-Type" header of the response
# Try an image URL!
aws = "3.130.255.192"
response = requests.get("http://" + aws)
print(response.text)
Configuration
server {
// Listen on virtual "port 80"
listen 80;
listen [::]:80;
server_name 3.130.255.192;
location / {
// Inform server about original client
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
// Forward all requests transparently to the server running on our computer
proxy_pass http://localhost:9099;
}
}
Load Balancing
upstream example.com {
server server1.example.com;
server server1.example.com;
}
HTTP Headers
server {
add_header X-Cool-Header "I love APCSP!";
location /pages {
add_header X-Cooler-Header "This is my secret header!";
}
}
Check In
- Research 1 HTTP header and describe, in detail, its purpose.
One commonly used HTTP header is the "User-Agent" header. The User-Agent header provides information about the client making an HTTP request, typically in the form of a web browser or an application. It helps the server understand what kind of client is making the request, enabling it to provide a response tailored to the client's capabilities or requirements.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
location
See Below
- Explain the purpose of the load balancing performed by NGINX
The load balancing feature in NGINX distributes the incoming requests evenly across multiple servers. This helps improve the performance and reliability of the website as well as ensure that one server is not overwhelmed.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
For number 2
server { add_header X-Cool-Header "Claire Zhao";
location /information {
add_header X-Cooler-Header "Specific Header";
}
}
aws = "3.130.255.192"
response = requests.get("http://" + aws+ "/products")
print("The secret header is:", "...")
print(response.headers)
Slides Hacks
- What does DNS stand for?
Domain Name Service
- What is the purpose of DNS?
It's purpose is to translate human-readable domain names into the numerical IP addresses that computers and network devices use to communicate with each other.
- How does DNS work?
A user types a domain name into their web browser, the browser sends a request to a DNS server to look up the IP address associated with that domain name. The DNS server then responds with the corresponding IP address, allowing the browser to establish a connection and load the requested website.
- What is a DNS resolver?
A DNS resolver is like a translator that converts domain names (e.g., www.example.com) into the numerical IP addresses (e.g., 192.0.2.1) needed for computers and network devices to communicate over the internet.
CORS Hacks
- Explain what CORS is and what it stands for
CORS stands for cross-origin security. CORS is a security mechanism implemented in web browsers to protect users from potential malicious activities that can occur when making requests across different origins
- Describe how you would be able to implement CORS into your own websites
When reading from the API that is given in the project we used mode CORS. This was done in the read function and was in Javascript brackets.
- Describe why you would want to implement CORS into your own websites
CORS is able to protect the website from bad activity and that will allow for more security especially since my website has personal information stored.
- How could use CORS to benefit yourself in the future?
Add to future websites to make sure that data is not stolen and have the best security in the website for the users experience.
Total: 0.2 points
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal?
Adding administrative properties when running. This needs access and permissions which is why we use a password when running anything that has sudo in it.
- What are some commands which allow us to look at how the storage of a machine is set up as?
df: Run the command df -h in the terminal to view information about file system disk space usage, including the device, total size, used space, available space, and mount points.
diskutil: Run the "diskutil" command-line utility to view information about disks and partitions. Open the Terminal and type "diskutil list" to see a list of all the disks and partitions on your system.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
Using a web browser allows for the zip file for KASM to be downloaded. You can just download it from the website and have access to the zip file.
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
setting permissions, create directory, and install softwares or packages
- Explain in at least 3-4 sentences how deploying KASM is related to/requires other topics talked about in the lesson and/or potential ways to add things mentioned in the lesson to this guide.
Application isolation, security, load balance, and remote access are just a few of the associated subjects that must be understood in order to deploy KASM. It is necessary to grasp security concepts and best practices in order to use KASM, which offers a secure and isolated environment for running applications. KASM can be accessed remotely, but doing so requires familiarity with the relevant tools and protocols. Load balancing is needed to distribute traffic equally among several server instances running KASM. These are all topics of how KASM is related to the lesson talked about before.
Total: 0.2 points