ssh 后的主目录

home directory after ssh

我正在我大学的 server/cluster 上开发一个网络应用程序,它有我所有的代码,我想 运行 在后端。

我会先 post 我的一般问题,然后是我得到的详细代码和错误消息。我的主要问题是,当我通常在我的计算机上本地开发任何使用 python 和微框架或框架(如 flask 或 django)的网络应用程序时,我访问浏览器上的地址,以确保一切正常运行宁是:http://0.0.0.0:5000, or something around localhost. However, when I've ssh'ed to the server/cluster, what would my new address be? Suppose I ssh to user@cluster1.uni.ece.edu. Should I be able to see the output of my website by going to http://cluster1.uni.ece.edu ?

详细规格:

我 运行ning 的代码应该允许任何人通过 Web 浏览器将图像从客户端上传到服务器。

import os

from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename

# Initialize the Flask application

app = Flask(__name__)

# This will be th path to the upload directory
app.config['UPLOAD_FOLDER'] = 'uploads/'

# These are the extension that we are accepting to be uploaded
app.config['ALLOWED_EXTENSIONS'] = set(['png','jpg','jpeg'])

# For a given file, return whether it's an allowed type or not
def allowed_file(file_name):
  return '.' in filename and \
    filename.rsplit('.',1)[1] in app.config['ALLOWED_EXTENSIONS']

# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the 
# value of the operation

@app.route('/')
def index():
  return render_template('index.html')

#Route that will process the file upload
@app.route('/upload',methods=['POST'])
def upload():
  #Get the name of the uploaded file
  file = request.files['file']
  #Check if the file is one of the allowed types/extensions
  if file and allowed_file(file.filename):
    #Make the filename safe, remove unsupported chars
    filename = secure_filename(file.filename)
    #Move the file from the temporal folder to
    #the upload folder we setup
    file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
    #Redirect the user to the uplaoded_file route, which
    #will basically show on the browser the uploaded file
    return redirect(url_for('uploaded_file',filename=filename))


# This route is expecting a parameter containing the name of a file.
# Then it will locate that file on the upload directory and show it on the
# browser, so if the user uploads an image, that image is going to be shown
# after the upload.

@app.route('/uploads/<filename>')
def uploaded_file(filename):
  return send_from_directory(app.config['UPLOAD_FOLDER'],filename)


if __name__ == '__main__':
  app.run(
    host='0.0.0.0',
    port=int("80"),
    debug=True
  )

上面的代码是从另一个网站上的教程借来的。无论如何,我得到的错误是这个:

 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
Traceback (most recent call last):
  File "Demo1.py", line 60, in <module>
    debug=True
  File "/home/arturo/miniconda/envs/venv1/lib/python2.7/site-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/home/arturo/miniconda/envs/venv1/lib/python2.7/site-packages/werkzeug/serving.py", line 618, in run_simple
    test_socket.bind((hostname, port))
  File "/home/arturo/miniconda/envs/venv1/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied

我的一个朋友正在开发一个类似的网站,他设法让它运行起来:http://cluster1.uni.ece.edu:8000/Demo1

你的第一个问题的答案是肯定的。如果您 运行 服务器中的 Web 应用程序,您将能够看到网站的输出。默认情况下,该应用程序将 运行 在端口 5000 上。

对于第二期,请检查此问题的答案:socket.error: [Errno 13] Permission denied。您在非root用户的情况下将开发服务器的端口更改为80。 运行 你的申请是这样的:

if __name__ == '__main__':
  app.run(
    host='0.0.0.0',
    debug=True
  )

您将能够在 http://cluster1.uni.ece.edu:5000 中看到输出。 如果你想在 80 端口上 运行 它,你必须有 root 访问权限。 如果你想部署它,我会推荐你​​使用像 Apache or Nginx 这样的生产服务器。