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
Related
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.
Ive looked at this for hours, but am still not getting where I need to get to despite doing a lot of hours googling.Nginx is throwing no input file specified
my config in /etc/nginx/sites-enabled/siteb looks like:
upstream site {
#flask app
server 127.0.0.1:8001;
}
upstream siteb-blog {
#wordpress php
server unix:/var/run/php5-fpm.sock;
}
server {
server_name siteb.com;
listen 80;
root /home/www/flask-deploy/siteb;
location ~* ^blog/ {
try_files $uri $uri/ /blog/index.php?$query_string;
root /home/www/flask-deploy/siteb-blog;
location ~ \.php$ {
fastcgi_pass siteb-blog;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location / {
try_files #proxy #proxy;
}
location #proxy {
internal;
proxy_pass http://siteb;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /home/www/flask-deploy/siteb/static/;
}
}
However, when i try to access mysite.com/blog or mysite.com/blog/info.php i get a 404 error.
ive checked error.log and it doesnt show any errors. access.log, just shows:
[16/Dec/2016:16:11:56 -0500] "GET /blog/index.php HTTP/1.1" 404 209 "-" "Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:50.0) Gecko/20100101 Firefox/50.0"
My siteb.com works fine. siteb.com/blog does not.
im specifically trying to get siteb-blog working at siteb.com/blog.
Thank you in advance!
You have WordPress installed under a directory called siteb-blog and would like to access it with a URI prefix of /blog/. One of your problems is that the $request_filename is constructed from the root and URI, so that the /blog segment becomes part of the pathname. See this document for details.
The simple solution with static files is to use the alias directive, but I try to avoid using it with try_files because of a long standing bug.
My preferred solution is to silently (using internal rewrite) map the /blog URI to /siteb-blog, then continue to use root as normal.
For example:
server {
server_name siteb.com;
listen 80;
location /blog {
rewrite ^/blog(.*)$ /siteb-blog$1 last;
}
location /siteb-blog {
root /home/www/flask-deploy;
try_files $uri $uri/ /blog/index.php?$query_string;
location ~ \.php$ {
try_files $uri /blog/index.php;
fastcgi_pass siteb-blog;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location / {
proxy_pass http://siteb;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
root /home/www/flask-deploy/siteb;
}
}
You can make the location /siteb-blog internal, by adding the internal directive. This will make it inaccessible directly.
A root statement in both the server block and the location /static block is unnecessary - it only needs to appear once.
The alias was unnecessary - root is preferred. See this document for details.
The named location was unnecessary - merged with location /
Finally, WordPress needs to know that it is hosted under /blog, otherwise it cannot find its resource files (css & js). You will need to set the values for WP_SITEURL and WP_HOME either using wp-config.php or using the WordPress ⇒ DashBoard ⇒ Settings ⇒ General page.
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 a server with a name of compute01.com
I have a python django application through a reverse proxy, a gitlab instance, a mediawiki php instance, and a wordpress php instance on this server.
my goal is to have the urls set up as:
compute01.com/django/
compute01.com/gitlab/
compute01.com/wiki/
compute01.com/wordpress/
so far I only have gitlab running with its own sites-enabled file
server {
listen compute01.com:80 default_server;
##listen [::]:80 default_server;
server_name compute01.com;
server_tokens off;
root /home/git/gitlab/public;
client_max_body_size 20m;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location /gitlab {
try_files $uri $uri/index.html $uri.html #gitlab;
}
location /django {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
I added the django location added to this file because its the only I way I can add that relative url to talk to the wsgi. however 404s and such get redirected to gitlab.
What I would like is four separate files in sites enabled that have the individual urls and location blocks however I am not sure what the structure would be, would it be " 4 servers" or "4 locations at a server"?
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.