Getting Terminal to do something else while running a localhost on it. - python

How come I can't do anything else on terminal when It's running a localhost. Like I run a google app engine on it and make a new local host, I for example try to see what directory I'm in or even change directories, it doesn't respond to any of my requests? Thank you

That instance of the terminal will be busy doing the thing you asked it to. But you can just open a new window or tab.

Related

I've created a simple .onion site, but instead of the Tor browser displaying my index.html file, it displays my folders

This is my first question so please bear with me. I looked for answers to my question, but found none unique to my issue.
I recently tried my hand at hosting an onion site with Python3 and the Tor browser. I created a directory called "tor_service" and placed a simple index.html file inside.
I then ran python3 -m http.server --bind 127.0.0.1 8080 in the same folder. Next, I opened another terminal session and started the Tor client. I navigated to, and appropriately modified the torrc file under the "hidden services" section, using port 8080. I opened my browser and went to localhost:8080 to verify everything was working. To my surprise, I saw the simple web page I wrote. So far, so good.
I then navigated to the Tor folder that contained the hostname to get the unique oinion address, and using cat hostname, obtained the string of characters followed by .onion.
I pasted the onion address in the Tor browser and again, I saw the simple html page I wrote.
Here's the problem: when I shut down my computer for the night, resumed the next day, and started the Python server and Tor client, instead of displaying my web page, I got a page that read "Directory of /" that displayed all of the folders on my hard drive. This is obviously a serious security issue. Not only were the folders on my hard drive on display for the web to see, they were all hyperlinks.
I don't understand what I did wrong. I didn't modify or move any files or change any settings, and I started the Python http.server and Tor client as usual.
I closed the terminal windows opened new ones, but got the same results. A third time resulted in the same outcome. I understand that using the Python "server" isn't the optimal method to host a site, but if I can't get something so simple to work, I fear I won't be able to actually write (much less diagnose problems on) a more robust server that operates using more than a single line of code.
I'm using the Linux subsystem on Windows 10 and the latest iteration of Ubuntu (20.4, I think).
Any pointers are greatly appreciated. I can craft and style a nice looking webpage, but I'd like to get proficient at the back-end side of things.
Are you sure you have navigated back to the project folder in your terminal?
If you're running the
python3 -m http.server --bind 127.0.0.1 8080
command immediately after opening the terminal, it will run in the 'default' folder rather than your project folder (you'll need to 'move' back into the project folder using cd).

Stop Python localhost server on every port

Since I tried a tutorial with Python / Django using venv etc, i'm blocked with a localhost server that shows folder of this project:
I use Visual Studio Code and I use LiveServer configured on port 0. Each time I want to start LiveServer, it renders me this page and nothing else.
Have you any idea why and how to stop it?
I modified my PATH folder to make the Python's project work. Is it the problem?
Thank you
The way to fix this is by going to VS Code >> File >> Open Folder, and the select the folder with your html file in it then you can run live server properly. However, if you want to stop live server simply closing the web browser it's running on will do.

Localhost port running even after kill and freeing the port

This is a curious situation:
Python folder
Let us say the path is ~/pyfolder/
I run the command python -m SimpleHTTPServer 8080 inside the folder. Now on localhost:8080, I get index.html which is inside the pyfolder.
I stop the server by killing the process, check that nothing is going on the port 8080.
Node folder
Let us say the path is ~/webfolder/
I run PORT=8080 node server.js inside the folder. I expect to see ~/webfolder/index.html(i have setup express js route for / to show this file) on port 8080. But what is see is ~/pyfolder/index.html. This is weird.
Furthermore, when a call is made to 8080, node console show a request being made on the port which is handled by express but still the page shown is from the python folder.
Can someone explain what is the problem here?
EDIT:
Also, the happens only on browser without incognito mode. As soon as I try this in incognito mode, everything runs fine.

Running flask app on DigitalOcean: should I keep the ssh console open all the time?

I created a droplet that runs a flask application. My question is when I ssh into the droplet and restart the apache2 server, do I have to keep the console open all the time (that is I should not shut down my computer) for the application to be live?
What if I have a dynamic application that runs scripts in the background, do I have to keep the console open all the time for the dynamic parts to work?
P.S:
there's a similar question in SO about a NodeJs app but some parts of the answer they provided are irrelevant to my Flask app.
You can use the "screen" command to mantain the sesion open.
please see https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/
In my opinion it is not a good practice to use remote computers for the development stage unless you don't have an other option. If you want to make your application available after logging out from the ssh console, screen works, but it still a workaround.
I would suggest taking a look at this great tutorial on how to daemonize flask applications with Gunicorn+Nginx.
You needn't keep the console on, the app will still running after you close the console on your computer. But you may need to set a log to monitor it.

While running google app engine application I encountered Bind error? [duplicate]

I am trying to run a Python app in Google App Engine. The UI doesn't work so I tried using the command lines. I tried restarting my PC, I tried changing port with "dev_appserver.py --port=9999 ." but it still says Unable to bind localhost:8000:
raise BindError('Unable to bind %s:%s' % self.bind_addr)
google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to bind localhost:8000
The app server starts two servers; one for your application, the other for the development console. It is that second server that is causing the problem here; it normally would be run on port 8000.
Change the ip address for the development console with the --admin_port switch:
dev_appserver.py --admin_port=9000
You may still want to change the port for the main application server too, of course.
Also see the command-line arguments documentation for dev_appserver.py.
It is possible some application is binding to your port in autostart event.
It's highly probable to be the same service you are trying to run. In that case try killing the process
ps -ef | grep 'process_name'
Use kill -9 'pid' to end the process.
A computer restart did it, closing google app engine launcher, restarting the computer then launching again did the trick...
terminate old terminal and start in new, its the easiest way I
could find
Being unable a port is usually a sign of one of two things:
You don't have permissions
Something is already running there.
You can try hitting the local port 8080 with your browser to see what is there, and kill it if it shouldn't be.
As for permissions - only look for this afterwards. Presuming you are in windows (you didn't specify this), then you should be able to bind this as a normal user.
As for the command line - have you tried replacing the "=" with a space - I've seen both forms in documentation for app-engine.
dev_appserver.py --port 9999 .

Categories

Resources