I am trying to create a wordpress website that uses nginx as a reverse proxy to apache - apache serves only php requests.
I was able to successfully install wordpress but whenever I try to open the website it says "too many redirects". However when I try to open example.com/wp-admin it loads and I am able to login into and access the admin panel.
My /etc/nginx/sites-available/webproxy is:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name server_ip;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
}
I checked both apache and nginx error logs - empty.
Related
I am trying to run reactjs application and PHP application together on Nginx.
Reactjs application runs well, but I am unable to run PHP application.
I have added two server blocks for both the applications but unable to run PHP app which is actually my api/service for react js app.
Any help in this regard would be much appreciated.
Here is my nginx configuration for react js application:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/qurancom-reactjs;
index index.html index.htm index.nginx-debian.html;
server_name 3.16.130.108;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3000;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
and here are my php app nginx server block configurations:
server {
listen 80;
listen [::]:80;
root /var/www/html/quran-app-services/api;
index index.php index.html index.htm index.nginx-debian.html;
server_name 3.16.130.108;
location / {
try_files $uri $uri/ =404;
}
}
Thanks
I am an amateur front end web developer, and I recently bought a Ubuntu server to try to my hand at some backend development. I am trying to figure out how to serve a php file from an aliased location block using php5-fpm. I am getting a 404 - Page not found error. I have tried all of the proposed solutions I could find here with no luck. As I am still a beginner I would love a quick ELI5 as well and any pointers on the rest of my conf file, so I can learn something too. I should mention that the main root folder is running a flask app, and is the reason I am using an aliased location.
My virtual host:
Nginx conf file
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
root /var/www/example;
large_client_header_buffers 8 32k;
access_log /var/www/example/logs/access.log;
error_log /var/www/example/logs/error.log;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr; #$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_test;
proxy_redirect off;
}
location /test_site {
alias /var/www/test_site;
index index.php index.html index.htm;
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
fastcgi_pass unix:127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
php5 www.conf file
[www]
...
user = www-data
group = www-data
listen = 127.0.0.1:9000
#listen = /tmp/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
...
My fastcgi_params file is default. I have checked both the php and nginx logs and there are no errors. Any help would be much appreciated!
Getting alias to work with nested locations using fastcgi is complicated.
Assuming that you have not over simplified your configuration, the test_site location does not need to use alias:
location /test_site {
root /var/www;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:127.0.0.1:9000;
include fastcgi_params;
}
}
This removes the alias directive, and solves the aliasing problem in the PHP block.
Note also: The regex on the location ~ \.php$ block was wrong. The fastcgi_split_path_info and fastcgi_index directives are unnecessary.
The nginx directives are documented here.
I have an Ubuntu VPC. I have a nodejs app running on it in some folder. I have a php app running on apache in var/www. What I want is to configure nginx so that when a user comes on mydomain.com , he/she is redirected to my node app running on port 3000 and when the user visits mydomain.com/docs , he/she is redirected to my php app running on apache on port 80.
server {
listen 80;
root /var/www;
location / {
try_files $uri $uri/ /index.html;
}
location ~\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~/\.ht {
deny all;
}
}
My conf file for nodejs app is:
upstream app_somedomain {
server 127.0.0.1:3000;
}
server {
listen 0.0.0.0:80;
server_name mydomain.com mydomain;
root /some/path;
index index.html index.htm index.php index.js;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_somedomain/;
proxy_redirect off;
}
}
I am using nginx for the first time. I am still unable to understand how to achieve this. As in how to serve my nodejs app running on port 3000 to my domain name and mydomain/docs to my php app.
Thanks.
I have vps using nginx on that web server I got 2 conf (host1.com,host2.com) files on /etc/nginx/conf.d but 2 domain access to the same site. those site are on different technologies 1 PHP (Apache running on 88 ) and 1 python (gunicorn running on 5000) both site can be access from outside correctly using those ports.
site 1 conf
server{
listen 80;
root /var/www/host1.com/public;
index index.php index.html index.htm;
server_name host1.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:88;
}
location ~ /\.ht {
deny all;
}
}
host2 conf
server {
listen 80;
server_name host2.com;
access_log /var/log/nginx/fundacion.log;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Thanks in advance.
Restart nginx.
Clear your browser cache.
I was following this tutorial https://www.digitalocean.com/community/articles/how-to-configure-nginx-as-a-front-end-proxy-for-apache to have a setup where nginx handles static stuff and all php files ares handled by apache on a fresh ubuntu box.
Everything went smoothly and I installed a php script on the server.
However, it is not loading any .html files. All .php files are loading and working fine. Whenever browser requests a html file, the browser kind of redirects back to index.php (although the url ending with .html remains in the address bar)
I have double checked and I've done everything according to the tutorial. What might prevent nginx from loading html files?
This is my nginx config:
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
Below is the nginx error log:
http://d.pr/f/voxs