redirect static files to nginx using .htaccess - .htaccess

I'm running nginx for static files(images, scripts) on 81 port and apache with php on 80.
Is it possible to redirect with .htaccess all iamges, styles, scripts requests to the same url but 81 instaed of 80 port?
I'm not very familiar with mod_rewrite
something like
if mysite.com/path/file.xxx has extension jpg or png or css
then redirect to mysite.com:81/path/file.xxx
thanks!

Normally you would do it the other away around: have Nginx proxy anything that's not a static file to a backend Apache. Having Apache look at all the incoming requests would defeat the purpose, since you use Nginx to avoid the inefficiencies of Apache when handling numerous requests. http://kbeezie.com/view/apache-with-nginx/ is a reasonable guide to the setup.

Related

Nginx .htaccess doesn't work in linux server

hi everyone i have just created website to myself and i editted links using .htaccess (111.111.111.111/list.php | like 111.111.111.111/list ) not include php extension. but when i put files into my linux server, it doesn't work my linux nginx server. when i write 111.111.111.111/list on the url box, it display 404 not found page. it wants to me write 111.111.111.111/list.php
and everything is working on my computer localhost. (i didnt buy domain name i just use only server's ip) please help me
by the way i apologize for my english.
Nginx does not support .htaccess-files because of performance reasons.
https://www.nginx.com/resources/wiki/start/topics/examples/likeapache-htaccess/
You have to do this inside of the nginx configuration file.
To remove the .php maybe this helps:
How to remove both .php and .html extensions from url using NGINX?
If you really need .htaccess, you have to use apache instead of nginx.

Node.js and Apache for single domain same server

I built a RESTful website, and it is written in Angular2(front end) and Php(backend). Since I am using Angular Universal, I need Node.js to pre-process the Angular scripts. How can I configure my server to host both Node.js and Apache? I searched online, but can't find any resources related to "sharing Node.js and Apache on SINGLE domain"...
How to configure my Apache to route "everthing" to the /dist/ folder (and served by Node.js) except for the URI that are prefix with /api/ and /uploads/ (route to the /php/ folder).
[Back-end] Api Php script:
If www.example.com/api/?...?, then use this script /var/www/example.com/public_html/php/api.php to process it.
Uploaded images:
If asking for uploaded img files (www.example.com/uploads/[img*.png]), then try to look inside this /var/www/example.com/public_html/php/uploads/[img*.png] folder.
[Front-end] Html, Js, etc...:
Everyting www.example.com (except the /api/ and /uploads/), then ask Node.js to run it from this /var/www/example.com/public_html/dist/ folder.
I guess it is related to proxy and proxy_http, but I don't know how to configure it since I can't find any resources related to sharing both systems for single domain...
i think you should Run Node.js on a different port (e.g 8080) and use Reverse proxy in Apache config (virtual hosts) like this:
ProxyPass /api http://www.example.com/php/
ProxyPassReverse /api http://www.example.com/php/
ProxyPass /uploads http://www.example.com/php/uploads/
ProxyPassReverse /uploads http://www.example.com/php/uploads/
ProxyPass / http://www.example.com:8080/dist/
ProxyPassReverse / http://www.example.com:8080/dist/
and then use htaccess rewrite rules for your uploads and api
you can read more about mod_proxy

Apache, Node, .htaccess

I have an apache webserver listening on port 80. With apache, a PHP/MySQL system based on Zend framework. And I also have a node server listening on port 3000.
When a client sends a request, always on port 80, it's therefore first handled by apache. I would like to apply the following rules before treating the request:
if content-type is "application/json" then
use apache web server
else if content-type is "application/zend" then
use apache web server
else
use node server
Here content-type is sent in the request headers. Content-type "application/zend" is a custom content-type to say that, for this type of particular request, we don't want to use node server (I need this for some reasons).
I've tried to modify httpd-vhosts.conf with
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
But that's of course not enough as not everything should be handled by the node server (listening on port 3000). Hence some rules should be added. But I'm unsure where/how. I also tried to change the .htaccess file, but not sure how either.
Any help would be great! Thanks!
This should work (in .conf file):
RewriteEngine on
RewriteCond %{HTTP:Content-type} !=application/json
RewriteCond %{HTTP:Content-type} !=application/zend
RewriteRule ^ http://%{HTTP_HOST}:3000%{REQUEST_URI} [P]
Keep in mind that this might carry a performance penalty, and if most of your requests end on node, we should perhaps search for better solution.

Nginx rejects urls like example.com/index.php/some/virtual/path

I just installed NGINX with default configuration and modified config only to accept PHP. PHP is working fine, but my NGINX is not recognizing urls like below:
example.com/index.php/some/virtual/path
How do I get NGINX to recognize such path? I am guessing it isn't recognizing the .htaccess file.
My HTACCESS file looks like this: http://pastebin.com/HQutZ9JL
My current Nginx configuration is: http://pastebin.com/AfFyS8J4
nginx does not support Apache .htaccess files. You will need to rewrite your ruleset in the nginx configuration file. From a quick look at your configuration file, I would start over and enable PHP using FastCGI instead of trying to recreate your specific configuration.

Tomcat and htaccess

Is it possible to execute .htaccess file on Tomcat?
We are trying to get phphgadmin to work and so far we can only load the first screen that display some folder links. When we click on them we get a 404 error and we suspect it might be URL rewriting.
You can't run phpmyadmin on tomcat, because tomcat can't interpret php (nor it can interpret .htaccess)
What you need is Apache HTTP server, and if you need to also run Java, use mod_jk or mod_proxy_ajp (comparison) - a way to let apache serve what tomcat "produces".

Resources