2

I have just brought a domain name (example.com) and have setup a URL frame redirection to my server's IP XXX.XXX.XXX.XXX, however I am getting a 403 forbidden error. I can access pages fine via the server IP. What I want is to copy the behavior of the server IP using my domain so I attempted to copy the virtual host for my IP but it doesnt work.

Here are my virtual host files:

server { 
    listen 80; 
    server_name example.com
    ;
    access_log /var/log/nginx/website.access_log;
            error_log /var/log/nginx/website.error_log;

            root /var/www;
            index index.html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /var/www/phpMyAdmin;
        include         fastcgi_params;
    }
}

And my current one for accessing the server by the IP directly (works):

server { 
    listen 80; 
    server_name xxx.xxx.xxx.xxx
    ;
    access_log /var/log/nginx/website.access_log;
            error_log /var/log/nginx/website.error_log;

            root /var/www;
            index index.php;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /var/www/phpMyAdmin;
        include         fastcgi_params;
    }
}

Here is my nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    autoindex off;


    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml                             application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/default;
    include /etc/nginx/sites-enabled/phpMyAdmin;
    include /etc/nginx/sites-enabled/example.com;


}

I have also tried:

sudo chown -R www-data:www-data /var/www
sudo chmod -R 775 /var/www

Any advice would be greatly appreciated. Been on this one for a while now.

Thanks!

EDIT ------

The problem was with my domain registrar, I had my domain setup as "URL forwarding", when it should have been "A record". This fixed it for me. Good luck all!

5
  • What do you see in the web server log files when this happens? Dec 6, 2014 at 12:55
  • Can you please paste out a few of Nginx log files? Dec 6, 2014 at 12:55
  • By the looks of it no error is written to either error.log or website.error.log. Interestingly, if I set autoindex on; I am redirected to the root folder (from whatever path I try to access). Here is what the access log looks like: [06/Dec/2014:08:55:44 -0500] "GET / HTTP/1.1" 200 339 "http://example.com/android_connect/OSM_PHP/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.62 Safari/537.36 OPR/26.0.1656.20 (Edition beta)"
    – Gmeister4
    Dec 6, 2014 at 14:00
  • I may just not be seeing it, but it seems like you're missing server_name example.com; in your config, so it's not matching your domain.
    – Nathan C
    Dec 6, 2014 at 22:04
  • If you solved this yourself, please post an answer and accept it. "Answers" do not belong in edits to the question; they will be missed there. Apr 18, 2018 at 21:37

1 Answer 1

1

I almost have same your problem but I solve it with this configuration If you have only one site on your server then you have to delete default configuration file . rm /etc/nginx/sites-available/default only leave /etc/nginx/sites-available/example.com with this configuration

server { 
    listen 80; 
    server_name example.com;
    access_log /var/log/nginx/website.access_log;
    error_log /var/log/nginx/website.error_log;
            root /var/www;
            index index.php  index.html;

    location / {
          try_files $uri $uri/ /index.php;
               }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /var/www/phpMyAdmin;
        include         fastcgi_params;
    }
}

if you want site acceptable via IP too you should create default configuration file

edit /etc/nginx/sites-available/default And use same configuration you used first

server { 
    listen 80; 
    server_name xxx.xxx.xxx.xxx;
    root /var/www;
    index index.php  index.html;
    location / {
          try_files $uri $uri/ /index.php;
               }
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /var/www/phpMyAdmin;
        include         fastcgi_params;
    }
 } 

Last you can move your site example.com file to /var/www/example.com and delete default configuration file then restart nginx

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .