DevOps Lesson
import socket
# Change the following host and see what IP it prints!
host = "google.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://www.netflix.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.
- Request headers contain details of the client requesting the resource.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
location
- Sorry, I don't know how to do this..
- Explain the purpose of the load balancing performed by NGINX Distribute incoming network traffic among multiple servers to increase application availability
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
import requests
aws = "3.130.255.192"
# send the GET requests to URL
# use get() to retrieve the value.
response = requests.get("http://" + aws+ "/products")
secret_header = response.headers.get('X-Secret-Header')
# If the header is present in the response, its value will be printed to the console.
# If the header is not present in the response, a message indicating so will be printed.
if secret_header:
print("The secret header is:", secret_header)
else:
print("The secret header is not present in the response headers")
CORS Hacks
- Explain what CORS is and what it stands for
- It stands for Cross-origin Resource Sharing. It allows the server to indicate any origin (domain, scheme or port) other than itself, from which the browser should allow resources to be loaded.
- Describe how you would be able to implement CORS into your own websites
- I can use this to determine if the browser is blocking responses from front-end JavaScript code from accessing cross-origin requests.
- Describe why you would want to implement CORS into your own websites
- JavaScript can only call URLs on the same origin as where the script is running, and if CORS is used, it will be able to call APIs on different domains
- How could use CORS to benefit yourself in the future?
- I will be able to access different schemes, different domains, different ports, although the URL being accessed is not the same as where JavaScript is running
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal?
- Run with administrator privileges
- What are some commands which allow us to look at how the storage of a machine is set up as?
- We can use df, du commands in linux to check it.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
- We can use "wget" command.
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
- It's a script command. It can be used for installing and save some time.
- 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.
- I think it is very similar to GitHub. It is a workspace. Through docker containers, it can reduce platform resource requirements and provide a secure environment.