Welcome! Log In Create A New Profile

Advanced

Re: nginx configuration issues

June 17, 2009 01:24PM
On Wed, Jun 17, 2009 at 05:44:19PM +0200, Joel Dahl wrote:

> Hi,
>
> I've been looking at replacing apache with nginx for a while and today I
> had some time over to play with the nginx configuration. I have around ~40
> websites and my goal is to set up nginx to handle more websites without me
> needing to reconfigure anything (I would like to avoid creating a new
> virtual host every time a new website needs to be created). This is just a
> test of course, and not anywhere near production.
>
> My nginx.conf looks like this (don't hesitate to suggest improvements, this
> is my first nginx.conf file after all):
>
> user www www;
>
> worker_processes 1;
>
> pid /var/run/nginx.pid;
> error_log /var/log/nginx_error.log;
>
> 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"';
>
> sendfile on;
> tcp_nopush on;
> tcp_nodelay off;
> keepalive_timeout 65;
>
> server_names_hash_bucket_size 128;
>
> gzip on;
>
> server {
> listen 80;
> server_name _;
>
> location / {
> root /home/w/$host;
> index index.php index.html index.htm;
> }
>
> error_page 500 502 503 504 /50x.html;
> location = /50x.html {
> root /usr/local/etc/nginx/errorpages;
> }
>
> error_page 404 /404.html;
> location = /404.html {
> root /usr/local/etc/nginx/errorpages;
> }
>
> location ~ \.php$ {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME /home/w/$host$fastcgi_script_name;
> fastcgi_param QUERY_STRING $query_string;
> fastcgi_param REQUEST_METHOD $request_method;
> fastcgi_param CONTENT_TYPE $content_type;
> fastcgi_param CONTENT_LENGTH $content_length;
> fastcgi_intercept_errors on;
> }
>
> location ~ /\.ht {
> deny all;
> }
> }
> }
>
> ...and at first it seemed to work. If the directory /home/w/www.foo.com
> exists, requests to www.foo.com works and I can see the website. However,
> if I try to access www.foo.com/bar I get a "can't find the domain
> www.foo.com" type of error message in my browser. Browsing to
> www.foo.com/bar/ works however, and www.foo.com/bar/index.php also works.
>
> What am I doing wrong? :)

Add

server {
server_name_in_redirect on;

otherwise nginx uses "_" as server name in redirect: "http://_/bar/".


--
Igor Sysoev
http://sysoev.ru/en/
Subject Author Posted

nginx configuration issues

Joel Dahl June 17, 2009 11:44AM

Re: nginx configuration issues

Igor Sysoev June 17, 2009 01:24PM

Re: nginx configuration issues

Joel Dahl June 17, 2009 02:20PM

Re: nginx configuration issues

Cliff Wells June 17, 2009 02:46PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 136
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