Welcome! Log In Create A New Profile

Advanced

Using Nginx as a Reverse Proxy, but php will not server through apache

Posted by goldcard 
Using Nginx as a Reverse Proxy, but php will not server through apache
August 12, 2009 08:07PM
I've spent a lot of hours being stuck, see the thing is that Nginx works with images and javascript, css and all static files great. Now the problem arises when I try to get Nginx to use Apache to serve php files. Nginx just refuses to allow Apache to server php files. note: I have my actual site url where it says mysite.com. I also must note that this still happens when nginx is listening on port 80 and apache is listening on 8080. I'm testing things backwards because I have active sites and no test server.

Here's mysite conf in /etc/nginx/sites-enabled:
[code]
server {
listen 8080;
server_name mysite.com alias www.mysite.com;
#access_log logs/mysite.access.log main;

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 ~ \.php$ {
proxy_pass http://127.0.0.1:80;

}


location / {
index index.html index.htm index.php index.shtml;
root /home/mysite/public_html;
}


}
[/code]



And here's my nginx.conf:


[code]
user nobody;
worker_processes 2;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

server_names_hash_bucket_size 64;
sendfile on;
tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_comp_level 5;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css image/x-icon
application/x-javascript;

gzip_vary on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

}
[/code]



Edited 1 time(s). Last edit at 08/12/2009 08:09PM by goldcard.
Re: Using Nginx as a Reverse Proxy, but php will not server through apache
August 13, 2009 07:43PM
I figured it out, I just put my sites name in the proxy pass so it looks like this:

[code]
location ~ \.php$ {
proxy_pass http://mysite.com:80;
}
[/code]

And it's port 80 because I'm testing this on a live site to see if I can find errors, so my next mission is getting mod rewrite to work.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 129
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready