Apache 2.4 module deployment not working - c++

I little new to Apache HTTP 2.4 server and its module development. I have been playing around and created one sample mod_hello.so module to test. But facing the issue while deployment : -
Issue : - Not able to deploy the mod_hello.so file in Apache http 2.4 server
Steps performed : -
Copied the mod_hello.so file into the /usr/local/apache/modules/
directory
edited the httpd.conf file to load the module :- LoadModule
foo_module modules/mod_hello.so
Restarted the httpd service
But when i try to access using URL :localhost/foo i get 404
not found error on browser. In Actual it should produce 'Hello Word'
Message on browser.
In the logs i also checked but couldn't be able to find anything useful
Prior to above activity i have done the following
Build the Apache server 2.4 from source and intalled on fedora 15 system
For building used APR, APR-UTIL, PCRE
Everything went properly and able to compile the sample code and got the desired mod_hello.so file
Any help to debug this issue is highly appreciated
Logs
error_log
AH00558: httpd: Could not reliably determine the server's fully
qualified domain name, using localhost.localdomain. Set the
'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully
qualified domain name, using localhost.localdomain. Set the
'ServerName' directive globally to suppress this message
[Wed Nov 12 13:48:17.753498 2014] [core:warn] [pid 13514:tid
3077613776] AH00098: pid file /usr/local/apache/logs/httpd.pid
overwritten -- Unclean shutdown of previous Apache run?
access_log
::1 - - [12/Nov/2014:12:58:06 -0800] "GET / HTTP/1.1" 200 45
::1 - - [12/Nov/2014:12:58:06 -0800] "GET /favicon.ico HTTP/1.1" 404
209
::1 - - [12/Nov/2014:12:58:06 -0800] "GET /favicon.ico HTTP/1.1" 404
209
::1 - - [12/Nov/2014:13:48:24 -0800] "GET / HTTP/1.1" 200 45
::1 - - [12/Nov/2014:13:48:32 -0800] "GET /foo HTTP/1.1" 404 201
::1 - - [12/Nov/2014:13:48:34 -0800] "GET /foo HTTP/1.1" 404 201
Solution
I have created one fresh conf file in apache/conf/extra/mod_hello.conf and added following lines in it
LoadModule helloworld_module modules/libhello.so
<Location /helloworld>
SetHandler helloworld
</Location>
After the above change put added following line into httpd.conf file
Include conf/extra/mod_hello.conf
Restarted the server
./httpd -X

Related

Flask app IP redirection is not working on Ubuntu

I have a Flask-based website, and working fine when I run on a local PC # localhost.
I cloned the app into the recently built Ubuntu PC and tried to host the website there. I installed Apache2 and and setup conffile # (sudo nano /etc/apache2/sites-available/000-default.conf) as follows :
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName 10.11.220.58
ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html
#DocumentRoot /home/user_name/imageFIFA/frameworks.ai.image-inference
WSGIScriptAlias / /home/user_name/imageFIFA/frameworks.ai.image-inference/app.wsgi
<Directory /home/user_name/imageFIFA/frameworks.ai.image-inference>
Order allow,deny
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog /home/user_name/imageFIFA/frameworks.ai.image-inference/logs/error.Log
CustomLog /home/user_name/imageFIFA/frameworks.ai.image-inference/logs/acess.log comb>
I created app.wsgi in flask project folder (/home/user_name/imageFIFA/frameworks.ai.image-inference) file as follows :
import sys
sys.path.insert(0,'/home/user_name/imageFIFA/frameworks.ai.image-inference')
from interceptor import app as application
My flask as is located at
/home/ad_pgooneti/imageFIFA/frameworks.ai.image-inference
When I run my front-end flask app and test the response with wget, I get the following :
--2022-09-17 12:24:36-- http://localhost:5000/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:5000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8943 (8.7K) [text/html]
Saving to: 'index.html'
index.html 100%[===================================>] 8.73K --.-KB/s in 0s
2022-09-17 12:24:36 (236 MB/s) - 'index.html' saved [8943/8943]
But If I use the server IP address of wget 10.11.220.58, I get the following :
--2022-09-17 12:29:43-- http://10.11.220.58/
Connecting to 10.11.220.58:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2022-09-17 12:29:43 ERROR 403: Forbidden.
So, I feel that redirection is not working. Apache2 server is running fine when I tested its status :
* apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-09-17 12:02:23 PDT; 29min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1392385 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 1392411 (apache2)
Tasks: 55 (limit: 19140)
Memory: 10.4M
CGroup: /system.slice/apache2.service
|-1392411 /usr/sbin/apache2 -k start
|-1392412 /usr/sbin/apache2 -k start
`-1392413 /usr/sbin/apache2 -k start
Sep 17 12:02:23 ImageFIFA systemd[1]: Starting The Apache HTTP Server...
Sep 17 12:02:23 ImageFIFA systemd[1]: Started The Apache HTTP Server.
Any help with why it's not running? The Flask app is running at default port 5000, but I am not sure where am I supposed to do that in conf and app.wsgi files.

vue front-end flask back-end integration

Below is my vue front-end build(npm rum build on vue-cli 3).
And below is my run.py file for flask back-end.
from flask import Flask, render_template
class CustomFlask(Flask):
jinja_options = Flask.jinja_options.copy()
jinja_options.update(dict(
variable_start_string='%%',
variable_end_string='%%',
))
app = CustomFlask(__name__,
static_folder="./dist",
template_folder="./dist"
)
#app.route('/')
def index():
return render_template("index.html")
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
as you can see, I've changed default flask static, template directory to ./dist due to my dist structure. But when I try to test my app, I got below messages.
Chrome console
vendor.97db904d.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.9aaff056.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.197e53a9.css Failed to load resource: the server responded with a status of 404 (NOT FOUND)
vendor.97db904d.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.9aaff056.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.197e53a9.css Failed to load resource: the server responded with a status of 404 (NOT FOUND)
flask
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/vendor.97db904d.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/app.9aaff056.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /css/app.197e53a9.css HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/vendor.97db904d.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/manifest.ce28c628.js.map HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/app.9aaff056.js HTTP/1.1" 404 -
How can I change properly static/template directory on flask? or should I change my build configuration on vue-cli3(webpack)? I have no more clue on this. Please give me a hint if you can. Thank you in advance.
If you change vue-cli build to put the content of the dist folder in the Flask static folder that would work.
However you'll need to change the way you initialize Flask app and serve index.html file.
# vue-flask.py
from flask import Flask
app = Flask(__name__, static_url_path='')
#app.route('/')
def index():
# changed to send_static_file
return app.send_static_file('index.html')
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
Here is the project structure:
I used the same approach in case of react and Flask integration but ended up splitting it down to two microservices as described here.
I've used this example in an app recently and it worked very well.
In particular the paragraph about configuring the redirects.

Elastic Beanstalk Laravel 5.4 Worker HTTP 500

I'm using Laravel 5.4 and after applying this package to my project and deploying it to my Elastic Beanstalk environment, messages in my sqs stay always in flight. I've done everything that the readme file says...
I followed every step but still got error 500 on POST /worker/queue requests.
Here's my worker log:
127.0.0.1 (-) - - [21/Jun/2017:01:36:59 +0000] "POST /worker/schedule HTTP/1.1" 200 92 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:37:59 +0000] "POST /worker/schedule HTTP/1.1" 200 92 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:38:59 +0000] "POST /worker/schedule HTTP/1.1" 200 92 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:39:59 +0000] "POST /worker/schedule HTTP/1.1" 200 92 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:39:54 +0000] "POST /worker/queue HTTP/1.1" 500 84128 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:40:59 +0000] "POST /worker/schedule HTTP/1.1" 200 92 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:41:13 +0000] "POST /worker/queue HTTP/1.1" 500 84128 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:41:13 +0000] "POST /worker/queue HTTP/1.1" 500 84128 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:41:13 +0000] "POST /worker/queue HTTP/1.1" 500 84128 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:41:13 +0000] "POST /worker/queue HTTP/1.1" 500 84128 "-" "aws-sqsd/2.3"
127.0.0.1 (-) - - [21/Jun/2017:01:41:13 +0000] "POST /worker/queue HTTP/1.1" 500 84128 "-" "aws-sqsd/2.3"
I have also been experiencing similar issues, and while I would need you to post some code, and more details as to what your doing, I can describe the steps I took to resolve my own issues.
You will need to be able to log into your instance in order to do some faster troubleshooting, so I suggest you set up eb ssh on your machines, or if you are using a VPC, create a Bastion host, to use to connect to the internal EC2s. Log into the app environment, go to /var/www/html, run php artisan tinker, and manually dispatch a job. If you are successful you will get a response with the id of the queued message, if not you will receive an error output, which you can further use to troubleshoot the issue. I also suggest checking whether the app is picking up the environmental values for the queues, so check whether the queue you set in the deployment configuration, matches the one your app is trying to send the request to.
If the message is successfully being sent to the queue, but you still have failing jobs, I suggest you SSH into the worker environment EC2 machine, and try to dispatch a job from there as well. In my personal scenario the worker environment was in the wrong security group, so it didn't have access to the database, resulting in a 500 error, due to an internal server issue.
Instructions on creating bastion hosts:
https://vaughanj10.github.io/creating-a-bastion-host-for-aws/

socketio client is sending thousands of GET requests django server as soon as the page is loaded

I am trying to develop a real time socket connection with django powered server built using gevent and greenlet. I started the server and the server is waiting on port 8000. But as soon as I load the page on the browser I see literally thousands of get requests (shown below) on the server terminal.
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648069-19838 HTTP/1.1" 200 172 0.004000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648074-19839 HTTP/1.1" 200 172 0.003000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648078-19840 HTTP/1.1" 200 172 0.003000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648083-19841 HTTP/1.1" 200 172 0.003000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648065-19837 HTTP/1.1" 200 172 0.004000
I am using version 1.0.6 of socket.io-client (https://github.com/Automattic/socket.io-client).
thanks,
I had this exact same problem, albeit with Express.IO on NodeJS and Socket.IO on the client side.
This issue will occur if the implementation versions of Socket.IO don't match between the client and server. For instance, there were a number of critical changes between Socket.IO v0.9 and v1.0. You need to either upgrade the one or downgrade the other.

Django + uwsgi + ngnix + debug off = Server Error (500)

I'm trying to set up a production server that consists of Django + uwsgi + Nginx.
The tutorial I'm following is located here http://www.panta.info/blog/3/how-to-install-and-configure-nginx-uwsgi-and-django-on-ubuntu.html
The production server is working because I can see the admin page when debug is on but when I turn to debug off. It displays the Server Error (500) again. I don't know what to do. Ngnix should be serving the Django request. I'm clueless right now, Can someone kindly help me, please.
my /etc/nginx/sites-available/mysite.com
server {
listen 80;
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite.com_access.log;
error_log /var/log/nginx/mysite.com_error.log;
location / {
uwsgi_pass unix:///tmp/mysite.com.sock;
include uwsgi_params;
}
location /media/ {
alias /home/projects/mysite/media/;
}
location /static/ {
alias /home/projects/mysite/static/;
}
}
my /etc/uwsgi/apps-available/mysite.com.ini
[uwsgi]
vhost = true
plugins = python
socket = /tmp/mysite.com.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /home/projects/mysite/mysite/wsgi.py
virtualenv = /home/projects/venv
chdir = /home/projects/mysite
touch-reload = /home/projects/mysite/reload
my settings.py
root#localhost:~# cat /home/projects/mysite/mysite/settings.py
# Django settings for my site project.
DEBUG = False
TEMPLATE_DEBUG = DEBUG
min/css/base.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/base.css HTTP/1.1", host: "160.19.332.22"
2013/06/17 14:33:39 [error] 8346#0: *13 open() "/home/projects/mysite/static/admin/css/login.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/login.css HTTP/1.1", host: "174.200.14.200"
2013/06/17 14:33:39 [error] 8346#0: *14 open() "/home/projects/mysite/static/admin/css/base.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/base.css HTTP/1.1", host: "174.200.14.2007", referrer: "http://174.200.14.200/admin/"
2013/06/17 14:33:39 [error] 8346#0: *15 open() "/home/projects/mysite/static/admin/css/login.css" failed (2: No such file or directory), client: 160.19.332.22, server: mysite.com, request: "GET /static/admin/css/login.css HTTP/1.1", host: "174.200.14.200", referrer: "http://174.200.14.200/admin/"
I think it's your ALLOWED_HOSTS setting (new in Django 1.5)
Try the following in your settings.py
ALLOWED_HOSTS = ['*']
This will allow everything to connect until you get your domain name sorted.
It's worth saying that when you do get a domain name sorted make sure you update this value (list of allowed domain names). As the documentation for ALLOWED_HOSTS states:
This is a security measure to prevent an attacker from poisoning
caches and password reset emails with links to malicious hosts by
submitting requests with a fake HTTP Host header, which is possible
even under many seemingly-safe webserver configurations.
Also (a little aside) - I don't know if you have a different setup for your django settings per environment but this is what I do:
At the end of your settings.py include:
try:
from local_settings import *
except ImportError:
pass
Then in the same directory as settings.py create a local_settings.py file (and a __init__.py file if using a different structure than the initial template) and set your settings per environment there. Also exclude local_settings.py from your version control system.
e.g. I have DEBUG=False in my settings.py (for a secure default) but can override with DEBUG=True in my development local settings.
I also keep all my database info in my local settings file so it's not in version control.
Just a little info if you didn't know it already :-)
I had the same issue but in my case it turned out to be that STATICFILES_STORAGE was incorrectly set as:
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
This question has already an accepted answer but I'm leaving this in case someone gets here in the same situation. You can also see this similar answer for the same error.