1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Migrating hosts from apache2 to nginx - help!

Discussion in 'Server Configuration and Hosting' started by Kainzo, Jun 22, 2013.

  1. Kainzo

    Kainzo Active Member

    I'm really confused on this process, I was able to transfer the files / databases just fine to the new host, but I'm having issues with how to convert to nginx for things to actually show up correctly.

    its herocraftonline.com/main << xenporta and herocraftonline.com/main/forum << forum

    I know this is a pretty bold request, but was hoping someone may be around to assist, I've tried searching the web but I may be missing some basic understanding of this.
     
  2. Tracy Perry

    Tracy Perry Well-Known Member

    Here is what is working on my forum currently. The first two server definitions remap apple4me.us and apple4me.org to apple4me.net, the third server definition strips the www from the request and routes it to apple4me.net.
    The location /nginx_status is used for munin to check stats on the web server and restricted to the IP's of my server (if you use this feature you need to change it or if not remove it).

    Code:
    server {
        listen 80;
        server_name www.apple4me.us apple4me.us;
        return 301 http://apple4me.net$uri;
    }
    
    server {
        listen 80;
        server_name www.apple4me.org apple4me.org;
        return 301 http://apple4me.net$uri;
    }
    server {
        listen 80;
        server_name www.apple4me.net;
        return 301 http://apple4me.net$uri;
    }
    server {
        listen 80;
        server_name apple4me.net;
    rewrite ^/(.*)/favicon.ico$ /favicon.ico last;
        error_log /var/log/nginx/apple-error.log warn;
        access_log /var/log/nginx/apple-access.log;
        root /var/www/apple4me;
        #end changes needed to begin
    location /nginx_status {
                    stub_status on;
                    access_log  off;
                    allow 127.0.0.1;
                    allow 199.48.164.159;
                    allow 24.49.69.204;
                    deny all;.
            }
       
        location / {
                #This sends everything through index.php and keeps the appended
                #query string intact.
                try_files $uri $uri/ /index.php?$uri&$args;
                index index.html index.htm index.php;
                rewrite /(robots.txt)$ /robots.php last;
        #gzip it, gzip it good
          gzip                    on;
          gzip_http_version      1.1;
          gzip_vary              on;
          gzip_min_length        1100;
          gzip_buffers            64 8k;
          gzip_comp_level        2;
          gzip_proxied            any;
          gzip_types              text/xml text/plain text/css application/json application/x-javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype application/xml application
          gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    
          # use fastcgi for all php files
            location ~ \.php$ {
            # Zero-day exploit defense.
            # http://forum.nginx.org/read.php?2,88845,page=3
            try_files $uri /index.php =404;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            }
    # Feed
                    location ~* \.(?:rss|atom)$ {
                    expires 1h;
                    add_header Cache-Control "public";
      }
    # Media: images, icons, video, audio, HTC
                  location ~* \.(?:jpg|jpeg|gif|png|ico|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
                  expires 1M;
                    access_log off;
                    add_header Cache-Control "public";
        }
    # CSS and Javascript
                  location ~* \.(?:css|js)$ {
                  expires 1y;
                  access_log off;
                  add_header Cache-Control "public";
        }
    # WebFonts expires
    # If you are NOT using cross-domain-fonts.conf, uncomment the following directive
                  location ~* \.(?:ttf|ttc|otf|eot|woff|font.css)$ {
                  expires 1M;
                  access_log off;
                    add_header Cache-Control "public";
        }
            #protect the innocent
            location ~ ^/community/(internal_data|library)/(.*)$ {
            internal;
            }
            # deny access to apache .htaccess files
            location ~ /\.ht
            {
            deny all;
        }
    }
     
    Last edited: Jun 22, 2013
  3. Kainzo

    Kainzo Active Member

    I see... and is all happening in the 'default' file (or website.com) in /etc/nginx/ ? I wish there was an easy way for me to push this to a test domain (I have 3) and then migrate it over heh... but not finding an easy way to do that atm.
     
  4. Tracy Perry

    Tracy Perry Well-Known Member

    In nginx you have two directories under /etc/nginx. They are /sites-available and /sites-enabled. In /sites-available I have the code I relayed in a file called apple4me. In /sites-enabled I have a symbolic link to that same file.
    If you are going to run multiple forums with different domains then you would have a file for each of them and then make a symbolic link for each in /sites-enabled.
     
  5. Kainzo

    Kainzo Active Member

    Right, I understand the sites-enabled/available.. and I have 3-4 sites coming up on the virtualmin assisted server. Just now trying to get this forum ported to a test domain first (Kainzo.com) so I can quickly change over once I can verify everything is sorted.

    God this is fun.
     
  6. Tracy Perry

    Tracy Perry Well-Known Member

    You did create the DB user and give it permissions to the DB you imported, correct? Once you set up the DB user it's a simple matter of importing it and if your DB name is the same and the username password you configured to have access the same then it should work.
    Used mysqldump to export the DB and mysql -p -u username database_name < file.sql to import it.
     
  7. Kainzo

    Kainzo Active Member

    Yah, I ninja edited my post after realizing I changed the password (for security) ... the only thing I have to work now is the mod_rewrite to ensure that the .php? extensions are changing to friendly. Ill have to play with it more tomorrow, most everything seems to be working thankfully!
     
  8. Tracy Perry

    Tracy Perry Well-Known Member

    If you used the example I gave it should use friendly URL's.
    Here is an example of one of mine: http://sayapple.com/threads/glas-t-screen-protector.1476/
     

Share This Page