I need to convert following nginx rule to Apache configuration.
can anyone help me.
location /chat {
rewrite /chat(/.+)$ $1 break;
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header Cookie $http_cookie;
proxy_buffering off;
proxy_send_timeout 310;
}
Have a look at the mod_proxy documentation, I think the ProxyPassMatch directive is of interest.
I would convert them to Apache2 like:
ReWriteEngine on
ProxyPreserveHost On
ProxyPass "/chat" "http://localhost:8000" flushpackets=on
ProxyPassReverse "/chat" "http://localhost:8000"
ProxyTimeout 310
in your <VirtualHost *:443> or <Location /chat> section
Related
(* As some comments recommended, I removed index.ejs and use index.html in the project by following this answer. So I have adjusted my OP *)
I develop in Mac with apache a MEAN-stack application that can be requested by
https://localhost:3000/#/home. In production with a nginx server, the application can be requested by
https://www.myapp.io/#/home. The fragment-identifier # is needed in all cases because of angular ui-router.
So I wanted to make pretty url without # (eg, https://www.myapp.io/home, https://localhost:3000/home) work. I have done the following:
1) added $locationProvider.html5Mode(true); $locationProvider.hashPrefix('') in app.config(['$stateProvider'....
2) added <base href="/" /> in index.html
As a result, https://localhost:3000/#/home changes automatically to https://localhost:3000/home in the browser bar, similarly for https://www.myapp.io/#/home.
However, directly entering https://localhost:3000/home or https://www.myapp.io/home in the browser will raise an error (I don't know how to turn previous <h1><%= message %></h1><h2><%= error.status %></h2><pre><%= error.stack %></pre> in error.ejs to error.html, so I don't have more details).
So now, the goal is to make https://localhost:3000/home and https://www.myapp.io/home work.
By following this thread, I added the follows to app.js:
app.use('/js', express.static(__dirname + '/js'));
app.use('/dist', express.static(__dirname + '/../dist'));
app.use('/css', express.static(__dirname + '/css'));
app.use('/partials', express.static(__dirname + '/partials'));
app.all('/*', function(req, res, next) {
res.sendFile('index.html', { root: __dirname });
});
And in apache of mac, here is my httpd-vhosts.conf, after restarting apache,
https://localhost:3000/home still returns an error.
<VirtualHost *:443>
ServerName localhost
DocumentRoot "/Users/SoftTimur"
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/apache2/ssl/localhost.crt
SSLCertificateKeyFile /etc/apache2/ssl/localhost.key
<Directory "/Users/SoftTimur">
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
In production, here is the nginx server block. After restarting nginx, https://www.myapp.io/home still returns an error.
server {
listen 443 ssl;
server_name myapp.io www.myapp.io;
ssl_certificate /etc/letsencrypt/live/myapp.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myapp.io/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EC$
ssl_session_timeout 1d;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
index index.html;
root /opt/myapp
location / {
try_files $uri $uri/ /index.html;
}
location ~ /.well-known {
allow all;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
proxy_set_header Proxy "";
proxy_pass https://127.0.0.1:3000;
# These three lines added as per https://github.com/socketio/socket.io/issues/1942 to remove sock$
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Could anyone help?
I think the better question you should be asking yourself is why don't you have index.html? Perhaps I've been asleep for too long, but browsers aren't really capable of executing JavaScript by itself on a webpage, without an underlying DOM from an HTML document.
Once you've got that figured out, you might as well succeed with the official configuration suggestion from angular-ui on GitHub.
Remove the nginx configuration you added. This can be achieved by performing the following:
There are 2 things that need to be done.
Configuring $locationProvider
Setting our base for relative links
See the following link for more detailed instructions on how to accomplish this:
Pretty URLs in AngularJS: Removing the #
For Angular 1.6 you will also need to change the hashPrefix:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');
}]);
I know in your question you stated that you had already done these two steps, but if you follow this tutorial perfectly it will work as I have tested this on my own Angular application (which is also hosted thru nginx).
To go with the server configuration route, I would recommend following this link:
AngularJS with Pretty URLs: Removing the # in Amazon S3
Additionally, here is the actual server configuration changes to make.
And lastly, I think you're mistaken with regard to how ejs works. It requires either HTML bootstrapping (after all, you must have some sort of index.html, with something like <script src="https://npmcdn.com/ejs/ejs.min.js"></script>), or processing on the server (e.g., with nodejs and/or friends).
Previously, I have hosted my NodeJS application with Apache proxy with following configuration in virtual-host.
<VirtualHost *:80>
ServerName api.mydomain.com
ProxyPreserveHost On
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now I have moved to NGINX because of GitLab dependency.
Now the virtual-host under /etc/nginx/sites-available/api.mydomain.com
server {
listen 80;
server_name api.mydomain.com;
location / {
proxy_pass http://localhost:8090;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
But the domain loads the main host content, not the nodejs app.
nginx version nginx/1.10.1, ubuntu version 16.04
Below is the only another virtual-host which I have for gitlab,
upstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
## Normal HTTP host
server {
## Either remove "default_server" from the listen line below,
## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
## to be served if you visit any address that your server responds to, eg.
## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
listen 0.0.0.0:80 default_server;
listen [::]:80 default_server;
server_name gitlab.mydomain.com
server_tokens off; ## Don't show the nginx version number, a security best practice
root /opt/gitlab/embedded/service/gitlab-rails/public;
## See app/controllers/application_controller.rb for headers set
## Individual nginx logs for this GitLab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
client_max_body_size 0;
gzip off;
## https://github.com/gitlabhq/gitlabhq/issues/694
## Some requests take more than 30 seconds.
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gitlab-workhorse;
}
}
You may have not created a symlink in sites-enabled pointing to the config in sites-available, so the configuration is not actually read.
I have been searching the Internet for a week now trying to find a good solution for this. First I read about http-master but I have been having issues installing it. Then I saw a few others that didn't have the features and ease of configurations. Or the answers were all outdated
We want to develop website in NodeJS, currently have three, two for test/dev and one for production. Each of these are hosted on the same server, currently an Apache server with the same domain name but different ports. We have another website we are working on as well with a different domain name.
Question is, what is the best way to use NodeJS to serve all the sites and more? Going forward we want to develop all applications in NodeJS.
Server Specs:
Windows Server 2012 R2
Two Cores
4 GB RAM
You want to use a reverse proxy. nginx is a good choice because configuration is so simple. But the same can also be achieved with apache.
Basically you just run each application under a different port, and based on domain name proxy over requests. Here's an example setup using nginx.
## Upstream www.example.com ##
upstream examplelive {
server 8081; # nodejs server running on port 8081
}
## Upstream dev.example.com ##
upstream exampledev {
server 8082; # nodejs server running on port 8082
}
## www.example.com ##
server {
listen 80;
server_name www.example.com;
access_log /var/log/nginx/log/www.example.access.log main;
error_log /var/log/nginx/log/www.example.error.log;
## send request back to examplelive ##
location / {
proxy_pass http://examplelive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
## dev.example.com ##
server {
listen 80;
server_name dev.example.com;
access_log /var/log/nginx/log/dev.example.com.access.log main;
error_log /var/log/nginx/log/dev.example.com.error.log;
location / {
proxy_pass http://exampledev;
proxy_set_header Host static.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
The below apache example should work.
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName www.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8081/
ProxyPassReverse http://localhost:8081/
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#dev.example.com
ServerName dev.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8082/
ProxyPassReverse http://localhost:8082/
</Location>
</VirtualHost>
My preferred way of hosting multiple domains has always been to use vhost with Express, which allows you to match different domain names.
var mailapp = connect()
var staticapp = connect()
// create main app
var app = connect()
// add vhost routing to main app for mail
app.use(vhost('mail.example.com', mailapp))
app.use(vhost('assets-*.example.com', staticapp))
If you don't want to go through the hassle of getting multiple domains pointing to this server, I find that using multiple sub domains on one primary name (e.g. foo1.bar.com, foo2.bar.com and using a CNAME record with your DNS to point to those subdomains is very effective.
will anyone help me with transferring configuration from Nginx to Apache2?
I dont know what to do with headers editing...
Thanks
According this:
https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr
server {
listen 80 default_server;
server_name $hostname;
#access_log /var/log/nginx/webvirtmgr_access_log;
location /static/ {
root /var/www/webvirtmgr/webvirtmgr; # or /srv instead of /var
expires max;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M; # Set higher depending on your needs
}
}
Found solution! Just make you sure, that you have libapache2-mod-wsgi installed
WSGISocketPrefix /var/run/apache2/wsgi
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.example.com
ServerName meinserver.xx
WSGIDaemonProcess webvirtmgr display-name=%{GROUP} python-path=/var/www/webvirtmgr
WSGIProcessGroup webvirtmgr
WSGIScriptAlias / /var/www/webvirtmgr/webvirtmgr/wsgi.py
Alias /static /var/www/webvirtmgr/webvirtmgr/static/
Alias /media /var/www/webvirtmgr/webvirtmgr/media/
<Directory /var/www/webvirtmgr/webvirtmgr>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
CustomLog ${APACHE_LOG_DIR}/webvirtmgr-access_log common
ErrorLog ${APACHE_LOG_DIR}/webvirtmgr-error_log
</VirtualHost>
i'm using CentOS release 6.5 (Final) and i installed nginx-1.6.1-1.el6.ngx.x86_64, httpd-2.2.15-31.el6.centos.x86_64 using yum
packets flow like below
external -> nginx:80 -> apache:8080
when i access server via http://test.zfanta.com always meet 403 error
error log
[Thu Aug 21 03:34:06 2014] [error] [client 211.49.54.233] (13)Permission denied: access to / denied
nginx setting
server {
listen 80;
server_name test.zfanta.com;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
proxy_pass http://127.0.0.1:8080;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X_FORWARDED_PROTO http;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
}
apache setting
Listen 8080
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
</Directory>
<Directory "/home/*/www">
AllowOverride FileInfo
Options FollowSymLinks Indexes
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot /home/zfanta/www
ServerName test.zfanta.com
ErrorLog logs/test.zfanta.com-error
CustomLog logs/test.zfanta.com
</VirtualHost>
and /home directory
/home/:
lost+found test zfanta
/home/lost+found:
/home/test:
www
/home/test/www:
index.html
/home/zfanta:
www
/home/zfanta/www:
index.php
I doubt this
Directory "/home/*/www"
would work (probably it would apply literally to directory /home/*/www, but won't expand). Since / is forbidden by the first Directory, you get that 403. Use something like this instead:
Directory ~ "/home/[^/]+/www"