Setup Roundup with WSGI and Apache - apache2

I was install Roundup 1.4 by Debian Squeeze official repo and want to run it with my Apache server using mod_wsgi. Host configuration:
<VirtualHost *:80>
ServerName support.domain.com
WSGIScriptAlias / /var/roundup/support/apache/roundup.wsgi
WSGIDaemonProcess support.roundup user=roundup group=roundup threads=25
WSGIProcessGroup support.roundup
<Directory /var/roundup/support>
<Files roundup.wsgi>
Order allow,deny
Allow from all
</Files>
</Directory>
# ... some logging configuration
</VirtualHost>
I was install tracker in /var/roundup/support using roundup-admin install, configure it and next initialise using roundup-admin initialise. Then I was created apache/roundup.wsgi:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
When opening my site at http://support.domain.com (ofcourse this url is bit different) I have HTTP response 500 Internal Server Error and log with:
mod_wsgi (pid=17433): Exception occured processing WSGI script '/var/roundup/support/apache/roundup.wsgi'.
RuntimeError: response has not been started
What's going on? How to run roundup with wsgi (not cgi) properly? Or where to look why response has not been started?
EDIT
Roundup's install manual says that wsgi handler would look like this:
from wsgiref.simple_server import make_server
# obtain the WSGI request dispatcher
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = 'demo'
app = RequestDispatcher(tracker_home)
httpd = make_server('', 8917, app)
httpd.serve_forever()
But this make no response. Browser loading it forever without message or server log. I think starting another server from script running by apache module isn't good idea. So I tried another code sample:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
from flup.server.fcgi import WSGIServer
WSGIServer(application).run()
But this throws some errors like:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
There must be a way to run my application from RequestDispatcher...

According to this issue this is an permission's problem. Solved using:
WSGIDaemonProcess support.roundup user=roundup group=roundup threads=25
WSGIProcessGroup support.roundup
where files in /var/roundup/support/ has roundup as owner and group with appropriate access permissions.

Try:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
All mod_wsgi needs is an 'application' object which is a valid WSGI application entry point.
You do not need to start a WSGI server or FASTCGI adapter yourself as you have been trying to do.

Related

how to deploy Next.js website on apache webserver [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 months ago.
Improve this question
I made React.js project , but it needs server side rendering, So now I have to migrate from CRA to next.js . the problem: I have to upload my website on apache web server, from what I gathered from google, I need installed node.js and pm2 (latest versions), also configured apache for reverse proxy. I also created ecoystem for pm2(I guess it was necessary). it looks like this at the moment:
module.exports = {
apps : [{
name: "nextjs-app",
script: "npm",
args: "run build",
env: {
NODE_ENV: "production"
}
}]
};
but when I ran pm2 start npm -- start , terminal is giving me respone like this:
pm2 start npm -- start
[PM2] Spawning PM2 daemon with pm2_home=/home/georgianar/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
[PM2] Done.
but when I try to see list of process, there is none, and when user tries to enter the website, site log shows that there is no service on port 3000
AH01114: HTTP: failed to make connection to backend: localhost
and
(111)Connection refused: AH00957: http: attempt to connect to 127.0.0.1:3000 (localhost:3000) failed
any idea why?
Well if you want to run both on the same server you can do it in many ways
To run both Node.js and Apache on the same server, follow these steps: https://nodejs.org/en/download/package-manager/
To run your Node.js application as a service, you can use multiple methods such as creating a service, using a process manager (PM2 is common), or running a script on server startup with a cron job. For more information, see this link: How do I run a node.js app as a background service?. You'll need a server start script, typically named server.js, to do this. An example can be found at Next.js: https://nextjs.org/docs/advanced-features/custom-server. To run the application manually in the background, navigate to the app directory and run node ./server.js &
Set up a tunnel using proxypass on Apache. This is commonly used to run the Node.js application on a specific URL. You'll need to install the Apache module mod_proxy and edit the configuration for your Apache server. An example configuration could look like this:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#example.com
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
You can also wrap the proxypass to run under a specific path using the location tag, like this:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#example.com
ProxyPreserveHost On
<Location "/mynodeapplication/">
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</Location>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
This will run your application at https://yoururl/mynodeapplication. For more information, see this link: https://httpd.apache.org/docs/trunk/mod/mod_proxy.html.
I hope this covers most of it.
To run Next on Apache, you'll need to set up the Apache settings so that when the domain or subdomain you want Next to run on is accessed, Apache points the request to the local port on the machine that's running Next. Another issue is that Next's built-in server doesn't support SSL (which I'm assuming you want), and using a custom server instead (like Express) loses you many features and optimizations that would otherwise just work with the Next server. So you'll not only need to have Apache redirect to Next, but also have Apache handle the SSL certificate.
To do this, specify a VirtualHost for the server on port 80 to redirect to HTTPS. For example, at least in Ubuntu, in etc/apache2/sites-available/000-default.conf, you can add:
<VirtualHost *:80>
ServerName subdomain.example.com
Redirect / https://subdomain.example.com/
</VirtualHost>
And then set up the SSL certificate for SSL requests (on port 443), and tell Apache to route client requests to the local machine port, and to route the local machine port's responses back to the client. If you're using LetsEncrypt, you can add this into 000-default-le-ssl.conf:
<VirtualHost *:443>
ServerName subdomain.example.com
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://0.0.0.0:16534/
ProxyPassReverse / http://0.0.0.0:16534/
SSLEngine On
SSLProxyEngine On
SSLCertificateFile <insert path to fullchain.pem>
SSLCertificateKeyFile <insert path to privkey.pem>
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
Above, I'm running Next on port 16534 - this is the port you'd see Next logging when it starts:
ready - started server on 0.0.0.0:49447, url: http://localhost:16534
so substitute it with whichever port you're using.
You'll also need to make sure the DNS server for your website points users to your webserver's external IP address by adding an A record, if you don't have one already. If the Next app is to run on a subdomain, you'll need a separate A record for the subdomain.

Apache2 conf file redirecting requests for other enabled sites

I'm running apache2 on ubuntu 16.04. I've configured apache2 to run multiple sites. One of the sites has https setup and to help support this I've added the following rule to redirect http requests to use https:
<VirtualHost *:80>
ServerName http://example.com
Redirect permanent / https://example.com/
</VirtualHost>
This has been too much of a blanket rule as it's redirecting other site's https requests to the domain above.
How can I re-configure the conf above to only redirect http requests for example.com and not the other sites on the same server?
The first listed virtualhost for each host:port acts as the default, catching all unmatched ServerNames. Make sure you don't define your special-case first.
See apachectl -S output for a summary of where your vhosts are loaded from and which one is the default.

How to configure Phoenix Framework behind Apache

I'm trying out Phoenix and for reasons beyond my control, I need it to be served through apache2.
There's a guide for serving Phoenix behind a proxy webserver but it only gives an example configuration for nginx (which I would be using if I could).
So I went to the documentation for mod_proxy and added these two lines to my VirtualHost:
<VirtualHost *:443>
...
LoadModule proxy_module modules/mod_proxy.so
ProxyPass /back http://www.example.com:4000 timeout=10
...
</VirtualHost>
I have the default Phoenix app running in development mode on port 4000. I tried going to https://example.com/back and the result is
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
I've checked my logs at /var/log/apache2/error.log and there is no error message corresponding to GET /back, although there IS a corresponding entry in access.log. All of the other things I'm serving are still working fine. I'm at a loss here, any pointers?
The problem was twofold.
Firstly, proxy submodules needed to be enabled.
sudo a2enmod proxy_http && sudo service apache2 restart
What led me to this fix was enabling a higher log level in apache2.conf:
LogLevel debug proxy:trace4
The relevant error was AH01144 (list of apache2 errors).
Secondly, I needed a reverse proxy:
<VirtualHost *:443>
...
ProxyPass /back http://www.example.com:4000 timeout=10
ProxyPassReverse /back http://www.example.com:4000 timeout=10
...
</VirtualHost>

Reverse Proxy Solr behind Apache Web server

I have an existing apache web server (2.2.15), configured with various security details (https only / authentication / authorization / etc.). I can rely on this server to handle the access requirements to my solr installation.
I have a basic 'example' solr instance up and running on a separate machine. (Solr 4.8.0 )
I want to be able to redirect the url https://myserver/department/team/search/.... to the Solr instance running on another (private) machine http://solrserver:8983/
I have configured the apache server with:
ProxyPass /department/team/search/ http://solserver:8983/
ProxyPassReverse /department/team/search/ http://solserver:8983/
I have some success with this, the https is being handled, the authentication/access is handled, and so on.
When I browse to the the url it is even loading up the basic solr page, but the page, internally, has the following:
<script type="text/javascript">
var app_config = {};
app_config.solr_path = '\/solr';
app_config.core_admin_path = '\/admin\/cores';
</script>
And that (I believe) is causing the JavaScript code to try to call:
https://myserver/solr/admin/cores?wt=json&indexInfo=false&_=1399485239437
Instead of
https://myserver/department/team/search/solr/admin/cores?wt=json&indexInfo=false&_=1399485239437
I believe these two values are configurable ( app_config.solr_path and app_config.core_admin_path ) but I cannot find out how/where to do it......
Questions:
How do I change the values set for the app_config.solr_path and app_config.core_admin_path?
Alternatively, this may be the wrong way to do this entirely, is there a better way to do it? (though the authentication/security provided by the apache webserver is perfect right now....)
This works for me.
<VirtualHost *:8080>
ServerName solr.xyz.com.br
ProxyPreserveHost on
ProxyRequests off
RewriteEngine On
RewriteRule ^\/solr(.*)$ $1 [L,R]
ProxyPass / ajp://localhost:8009/solr/
ProxyPassReverse / ajp://localhost:8009/solr/
</VirtualHost>
I know this might be out of context, but I would recommend replacing Apache with NGINX, much much simpler configuraiton. All you need is the following in nginx.conf:
location /solr/select {
proxy_pass http://YourSolrServer:8983/solr/select;
proxy_buffering on;
}
You can change the first /solr/select with whatever path you want (eg. /department/team/search/). So simple, so elegant.
Reference: https://groups.google.com/forum/#!topic/ajax-solr/pLtYfm83I98

ProxyPassMatch directive problems

We have an environment with Apache 2.2.11 acting as front end to incoming connections to a Tomcat backend server. We are using the following directives in the http-ssl.conf, which works great when not trying to catch 403 errors:
SetEnvIf COMPANY EDLP 4.0.1 NLEDLPKEY=true
General setup for the virtual host
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost:443
ServerAdmin admin#localhost
ProxyRequests Off
ProxyPassMatch / htp://tomcat.company.com**<-- been having issues with this directive (using only one "t" in http to bypass this sites new user can only post one URL per question limitation**
ProxyPassReverse / htp://tomcat.company.com
As you can see we are using the mod_access (now called mod_authz_host in Apache 2.2) module to pass a variable called NLEDLPKEY so that only (Internet Explorer) clients with this variable could access Tomcat via SSL. Also, I am trying to not only reverse proxy SSL connections, but also to redirect the 403 errors (for people without the variable) to a specified page (error_page.html). I have tried:
ProxyPassMatch "^[^(/error_page.html)]" htp://tomcat.company.com and also tried
ProxyPassMatch “^(?!/error_page.html)” htp://tomcat.company.com
to see if it is possible to redirect to the error page and not get the below message:
Forbidden
You don't have permission to access /RDS on this server. <--RDS is just a directory-->
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 Server at apache-company Port 443
Any help would be appreciated
R.
I ran into this issue recently - it took a bit of hunting but here's how I fixed it:
In /etc/apache2/mods-available/proxy.conf (Ubuntu - YMMV) change it to look like the following:
<Proxy *>
AddDefaultCharset off
Order deny,allow
Deny from all
Allow from all
</Proxy>
It's also important to note that for reverse proxies, it is not necessary to have ProxyRequests On configured and doing so in conjunction with Allow from all is hazardous. (Can be used by spammers to send mail via your proxy.)

Resources