How to fix (nginx error! The page you are looking for is not found.)?

Viewed 31

I faced this issue and tried many solutions on the internet, but I still can't fix it, This project is based on Python, Flask, Amazon Linux 2, and nginx.

My project path:

/home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI

/etc/nginx/sites-available/items-rest.conf Code:

server{
listen 80; 
real_ip_header X-Forwarded-For;
set_real_ip_from 127.0.0.1;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI/socket.sock;
uwsgi_modifier1 30;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html{
root /usr/share/nginx/html; 
}
}

/etc/nginx/sites-enabled/items-rest.conf Code:

server{
listen 80; 
real_ip_header X-Forwarded-For;
set_real_ip_from 127.0.0.1;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI/socket.sock;
uwsgi_modifier1 30;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html{
root /usr/share/nginx/html; 
}
}

/etc/systemd/system/uwsgi_asan_namaa_rest.service Code:

[Unit]
Description=uWSGI asan namaa

[Service]
Environment=DATABASE_URL=postgres:...
ExecStart=/home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI/venv/bin/uwsgi --master --emperor /home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI/uwsgi.ini --die-on-term --uid ec2-user --gid ec2-user --logto /home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI/log/emperor.log
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

uwsgi.ini Code:

[uwsgi]
base = /home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI
app = main
module = %(app)

home = %(base)/venv
pythonpath = %(base)

socket = %(base)/socket.sock

chmod-socket = 777

processes = 8

threads = 8

harakiri = 15

callable = app

logto = /home/ec2-user/projects/py_projects/asan_namaa/HeratGhardiAPI/log/%n.log

Project contents:

db.py  main.py  Pipfile       __pycache__       runtime.txt  static     uwsgi.ini
libs   ma.py    Pipfile.lock  requirements.txt  schemas      templates  venv
log    models   Procfile      resources         socket.sock  test.py

main.py Codes:

load_dotenv()

UPLOAD_FOLDER = 'my_uploads/'

app = Flask(__name__, template_folder='templates')
app.config[
    'SQLALCHEMY_DATABASE_URI'] = f"postgresql://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}@{os.getenv('DB_HOST')}/{os.getenv('DB_NAME')}"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["PROPAGATE_EXCEPTIONS"] = True
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = '...'

api = Api(app)


@app.before_first_request
def create_tables():
    db.create_all()
    # It is used for admin panel users to add, edit, or delete the data
    user_item = UserModel(name='admin', password='admin', is_admin=1)
    user_model = UserModel.find_by_name(user_item.name)
    if user_model:
        pass
    else:
        user_item.save_to_db()

    # Add first item to update checker because we just need to add one and then update it during live project and no
    # need to add multiple values
    update_item = UpdateCheckerModel(network_checker=1, urgent_num_checker=1)
    if update_item:
        pass
    else:
        update_item.save_to_db()


api.add_resource(SliderRes, "/sliders")
api.add_resource(SlidersResManipulate, "/slider/<int:sliders_id>")
api.add_resource(SliderImage, "/slider/image/<int:sliders_id>")

if __name__ == "__main__":
    db.init_app(app)
    ma.init_app(app)
    app.run(port=5000)

nginx version: nginx/1.20.0

Amazon Linux release 2 (Karoo)

Python 3.7.10

Flask 2.0.2

Werkzeug 2.1.2

And when I try this URL: http://PUBLIC_IP/slider I get this error: error.

0 Answers
Related