Change the Location of Nginx Installation Folder

I’m not sure whether anyone encounter the similar problem when installing Nginx where the installation folder is not your intended location and the ‘configure‘ command not working although you had re-generated the Makefile.

If I run the command: ./configure –prefix=/usr/local when installing NGINX, it will be automatically install the files to /usr/local directory and created several folders (e.g. conf, logs) into /usr/local directory. This is not what I want. The documentation stated that by default, Nginx will be installed in /usr/ local/nginx. I assume the installation will automatically create an ‘nginx‘ folder in /usr/local/ directory after the installation. I have no idea why it doesn’t work for me although there are several blogs mentioned that they able to installed it in /usr/local/nginx. Although I’m not sure whether this is the correct method to solve the problem but I decided to blog about this for my future reference.

 

Problem:

I would prefer the installation content in /usr/local/nginx instead of /usr/local because I hate unorganised files. Imagine the conf and logs folders in the directory without the information of the owner or the application.

  1. I tried to re-configure the path with the following command:
    sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module
  2. Run the command:
    make 
    make install
  3. Run the command to check any invalid command argument:
    nginx -V
    YEE-MACBOOK:~ mychin$ nginx -V
    nginx version: nginx/1.6.2
    built by clang 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local --with-http_ssl_module
    

    My latest command for the prefix configuration not working. It’s still taking the old prefix configuration command.

  4. Verify the configuration file with the command:
    nginx -t
    YEE-MACBOOK:local mychin$ nginx -t
    nginx: [alert] could not open error log file: open() "/usr/local/logs/error.log" failed (2: No such file or directory)
    2014/12/08 14:14:44 [emerg] 334#0: open() "/usr/local/conf/nginx.conf" failed (2: No such file or directory)
    nginx: configuration file /usr/local/conf/nginx.conf test failed
    

    Nginx still taking the old location: /usr/local instead of new one. For this reason, those two files cannot be found.

 

Solution

I tried several methods such as removed all the files, re-extract the downloaded zip file and reinstalled the nginx from scratch but this does not work. Logically, it should work if you had removed the folder with the installed content, install everything from scratch with a new specified path using ./configure command and re-generate the Makefile.

The only thing I didn’t delete was ‘nginx‘ executable file located in /usr/local/sbin directory. By default, the nginx executable file will follow the path: prefix/sbin/. If the latest path configuration (/usr/local/nginx) is not taking into effective, it means the nginx still using the old executable file, which is in /usr/local/sbin directory. Also, please note that /usr/local/sbin has been specified in the $PATH variable. For this reason, the new executable file (/usr/local/nginx/sbin) will never work.

  1. Remove the old executable file.
    cd /usr/local/sbin
    sudo rm nginx
  2. Ensure no more files related to nginx and the nginx command should be failed to work at the current stage.
    YEE-MACBOOK:sbin mychin$ nginx -t
    -bash: /usr/local/sbin/nginx: No such file or directory
    YEE-MACBOOK:sbin mychin$ nginx -V
    -bash: /usr/local/sbin/nginx: No such file or directory
  3. Re-install the nginx but with this command:
    sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module

    The summary of the installation path and everything goes well:

    nginx path prefix: "/usr/local/nginx"
    nginx binary file: "/usr/local/nginx/sbin/nginx"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"</li>
    
  4. Update the $PATH variable by making the entry in .bash_profile in home directory.
    sudo vi ~/.bash_profile
    export PATH=/usr/local/nginx/sbin:$PATH
  5. For immediate result for the changes to take effective.
    source ~/.bash_profile
  6. Ensure everything should be working well with the command:
    YEE-MACBOOK:sbin mychin$ sudo nginx -t
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    
    YEE-MACBOOK:sbin mychin$ nginx -V
    nginx version: nginx/1.6.2
    built by clang 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module

Install NGINX on Mac OS X 10.7 Lion

Before installing NGINX, you need to install Perl Compatible Regular Expressions (PCRE).

PCRE Installation

  1. Download and install PCRE from here: http://www.pcre.org/. The latest version (when this blog written) is 8.36.
  2. Extract the downloaded zip file (pcre-8.36.zip) in /usr/local.
    unzip pcre-8.36.zip
  3. Access to the extracted file
    cd pcre-8.36
  4. Configure the installation directory to /usr/local:
    ./configure --prefix=/usr/local
  5. Build and install the file
    sudo make
    sudo make install

 

NGINX Installation

  1. Download NGINX from here: http://nginx.org/en/download.html. The latest stable version is 1.6.2(when this blog written).
  2. Extract the tar.gz file to /usr/local.
    sudo tar xf nginx-1.6.2.tar.gz -C /usr/local/
  3. Access to the extracted folder.
    cd /usr/local/nginx-1.6.2
  4. Configure the directory for the server files and enable the http_ssl_module to for HTTPS support.
    sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module
  5. Build and install the file.
    make
    sudo make install
  6. By default, Nginx executable file will be installed in /usr/local/sbin directory. If you run ‘sudo nginx‘ and encounter error: ‘command not found‘, please check whether /usr/local/sbin is included in your $PATH by running this command:
    echo $PATH
  7. If /usr/local/sbin not found in the $PATH, you can update the $PATH with the following command:
    export PATH=$PATH:/usr/local/sbin
  8. You can ensure the config files are good before starting the server:
    sudo nginx -t
  9. Start nginx with the command:
    sudo nginx
  10. On the browser, access to localhost and if you setup the nginx successfully, this page will appear on your browser.

Nginx Installation Successful

Custom Tag for Google Search in Grails

I wanted to create a custom tag which can generate a Google link based from the provided search term in .gsp file. For example, a Google link will be generated if I provide the following line of code in the .gsp file:

<t:google term="Grails Example" />

In order to create a custom tag in Grails, you need to create a Groovy class which ends with the convention TagLib and place the file within the grails-app/taglib directory. I had created a class name called TaglistTaglib.groovy for my tag library definitions:

 class TaglistTagLib {

 static namespace="t"

def google = { attr, body ->

def skey = attr.term

out << "<a href="http://www.google.com/search?q=${skey.encodeAsURL()}">Search in Google</a>"

}

}

The output for the custom tag will look like the following screen:

Custom Tag Google Search

 

Reference:

http://grails.org/doc/latest/guide/theWebLayer.html#6.3 Tag Libraries

Custom JSP Tag Library using Struts

Second method: Struts

StrutsLink.java

package org.example.components;

import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.net.URLEncoder;
import org.apache.struts2.components.Component;

import com.opensymphony.xwork2.util.ValueStack;

public class StrutsLink extends Component {

    protected String term;

    public StrutsLink(ValueStack stack) {
        super(stack);
    }

    public void setTerm(String term) {
        this.term = term;
    }

    public boolean start(Writer writer) {
        try {
            if (term != null) {
                String query = URLEncoder.encode(term, "UTF-8");
                URL searchURL = new URL("http://www.google.com/search?q=" + query);
                writer.write("<A HREF=" + searchURL + " " + "TARGET="_BLANK">Search in Google</A>");
            }
            else {
                writer.write(writer.toString());
            }
        }
        catch (IOException e) {
            System.out.println("IOException error: " + e.getMessage());
        }
        return true;
    }

    public void googleSearch()
    {
    }

    public boolean end(Writer writer) {
        return true;
    }

    @Override
    public boolean usesBody() {
        return false;
    }
}

StrutsLinkTag.java

package org.example.tags;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.*;
import org.example.components.StrutsLink;

import com.opensymphony.xwork2.util.ValueStack;

public class StrutsLinkTag extends ComponentTagSupport {
    /**
     * 
     */
    private static final long serialVersionUID = 6901008022773665285L;
    protected String term;

    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
        return new StrutsLink(stack);
    }

    protected void populateParams() {
        super.populateParams();
        StrutsLink google = (StrutsLink) component;
        google.setTerm(term);
    }

    public void setTerm(String term) {
        this.term = term;
    }
}

custom.tld (/WebContent/WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
        "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
    <tlib-version>2.2.3</tlib-version>
    <jsp-version>2.0</jsp-version>
	<short-name>tags</short-name>
	<uri>/StrutsLinkTag</uri>
	<display-name>"Google Tags"</display-name>
	<description><![CDATA["Google"]]></description>
	<tag>
	    <name>search</name>
		<tag-class>org.example.tags.StrutsLinkTag</tag-class>
		<body-content>JSP</body-content>
		<attribute>
		    <name>term</name>
			<required>true</required>
			<description><![CDATA[ Term]]></description>
		</attribute>
	</tag>
</taglib>

linking2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="g" uri="/StrutsLinkTag"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Struts Linking</title>
</head>
<body>
	<h3>Struts URL</h3>
	<g:search term="Struts Tutorial" />
</body>
</html>

Struts URL

Reference:

http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/

Custom JSP Tag Library using SimpleTagSupport

I had created a custom taglib in two different methods. The first one is extending SimpleTagSupport and the second method is using Struts 2. The custom taglib is to generate a Google link with the search term.

First method: SimpleTagSupport

GenerateLink.java

package org.example.tags;

import java.io.IOException;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLEncoder;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class GenerateLink extends SimpleTagSupport {
    private String term;

    StringWriter sw = new StringWriter();

    public void setTerm(String tm) {
        this.term = tm;
    }

    public void doTag() throws JspException, IOException {

        googleSearch();

    }

    public void googleSearch() throws JspException, IOException {
        try {
            if (term != null) {
                String query = URLEncoder.encode(term, "UTF-8");
                URL searchURL = new URL("http://www.google.com/search?q=" + query);
                JspWriter out = getJspContext().getOut();
                out.println("<A HREF=" + searchURL + " " + "TARGET="_BLANK">Search in Google</A>");
            }
            else {
                getJspBody().invoke(sw);
                getJspContext().getOut().println(sw.toString());
            }

        }
        catch (JspException e) {
            // TODO Auto-generated catch block
            System.out.println("JSP exception error: " + e.getMessage());
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("IOException error: " + e.getMessage());
        }

    }

}

custom.tld (Created in /WebContent/WEB-INF)

<taglib>
  <tlib-version>1.0</tlib-version>
  <jsp-version>2.0</jsp-version>
  <short-name>tags</short-name>

  <tag>
    <name>google</name>
    <tag-class>org.example.tags.GenerateLink</tag-class>
    <body-content>empty</body-content>
    <attribute>
    <name>term</name>
    </attribute>
  </tag>
</taglib>

linking.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="t" uri="WEB-INF/custom.tld"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Non-struts URL</h3>
<t:google term="Struts Tutorial"/>
</body>
</html>

Non-struts URL

Reference

‘The Struts dispatcher cannot be found.’

Assuming the codes and the tag definitions in .tld file are working well, I need to run the application to perform the testing to check whether the custom tag can be applied on the jsp file successfully. After I restarted the Tomcat server, what I received are the following stakctrace appeared on the jsp file:

Stacktrace:] with root cause
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
 at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
 at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
 at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
 at org.apache.jsp.linking2_jsp._jspx_meth_g_005fsearch_005f0(linking2_jsp.java:108)
...
...
Jun 17, 2013 11:37:29 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/TagList] threw exception [An exception occurred processing JSP page /linking2.jsp at line 10
7: <title>Insert title here</title>
8: </head>
9: <body>
10: <g:search term="Struts Tutorial"/>
11: </body>
12: </html>

I did some research on google and I found the solution from here: The Struts dispatcher cannot be found error.  I added the following lines in WebContent/WEB-INF/web.xml:

<filter> 
<filter-name>struts-filter</filter-name> 
<filter-class> 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>struts-filter</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

The root cause of the problem has been discussed in detailed on the website mentioned above.

‘No signature of method’ Error When Creating A WAR File in Grails

When I tried to create a WAR file in Grails, the following stacktrace appeared on the console:

2013-06-11 21:58:31,381 [localhost-startStop-1] ERROR StackTrace - Full Stack Trace:
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.withDefault() is applicable for argument types: (org.codehaus.groovy.grails.plugins.services.ServicesGrailsPlugin$_closure1_closure4) values: [org.codehaus.groovy.grails.plugins.services.ServicesGrailsPlugin$_closure1_closure4@14a1ee92]
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058)
 at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:915)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 at groovy.lang.Closure.call(Closure.java:276)
 at groovy.lang.Closure.call(Closure.java:271)

 

Solution:

You need to check any unused or outdated plugins which you have installed into the project. As for my scenario, the root cause of the problem is the Struts 1 plugin which I thought it will not affect my project. However, judging from the stakctrace I received when creating the WAR file for the project, I guess there is a plugin or some plugins causing the stacktrace. Once I had removed the Struts 1 plugin from the project, I was able to generate WAR file for the project successfully.

Tomcat 7.0 Server Cannot be Defined in Eclipse

I want to define a new server (Tomcat 7.0) in Eclipse but unfortunately, I couldn’t proceed with the steps to create the server as both the ‘Next’ and ‘Finish’ button is grayed out and the server name is blank.

Add Tomcat Server in Eclipse

Solution:

As for my situation, the runtime environment was a bit messed up between the Tomcat version which I downloaded from the Apache website and the downloaded version via Ubuntu apt-get method. I had removed the version which was downloded via apt-get method but I forgotten to fix the runtime environment. In order to solve the problem, I need to access to Window -> Preferences -> Server -> Runtime Environments to fix the broken link for the server by removing the old one and update it with the new one which was downloaded from the Apache website itself.

If that is not the case for you, you can give it a try with the steps mentioned on this page: Eclipse 3.7 (Indigo) + Tomcat7 — Cannot create a server using the selected type

‘There is no Action mapped for action name’ in Struts

I had created the struts.xml file to for the actions mapping. I had mapped the actions in struts.xml but I’m still getting  the following error:

Jun 9, 2013 11:11:53 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Exception occurred during processing request: There is no Action mapped for action name create.
There is no Action mapped for action name create. - [unknown location]

 

Solution:

The root cause of the problem is I had misplaced the struts.xml. I placed the file in <project_name>/WebContent/WEB-INF folder. The correct folder path should be inside the <project_name>/WebContent/WEB-INF/classes folder. Once I had moved the file to the correct location, the application works well.

Upgrade to Grails 2.2 Causing Errors in views/index.gsp

I tried to upgrade Grails to a newer version, 2.2 and I received a long stacktrace on views/index.gsp after running the application. The stacktrace on views/index.gsp appears as following:

Error 2013-06-08 12:34:47,948 [http-bio-8080-exec-2] ERROR [/CustomerApp].[gsp] - Servlet.service() for servlet [gsp] in context with path [/CustomerApp] threw exception
Message: Error mapping onto view [/index]: Error evaluating expression [org.codehaus.groovy.runtime.InvokerHelper.getVersion()] on line [90]: groovy.lang.MissingMethodException: No signature of method: static org.codehaus.groovy.runtime.InvokerHelper.getVersion() is applicable for argument types: () values: []
 Line | Method
->> 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 679 | run . . . in java.lang.Thread
Caused by GroovyPagesException: Error evaluating expression [org.codehaus.groovy.runtime.InvokerHelper.getVersion()] on line [90]: groovy.lang.MissingMethodException: No signature of method: static org.codehaus.groovy.runtime.InvokerHelper.getVersion() is applicable for argument types: () values: []
->> 90 | doCall in /grails-app/views/index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Caused by InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static org.codehaus.groovy.runtime.InvokerHelper.getVersion() is applicable for argument types: () values: []

Errors index.gsp

Solution:

In order to resolve the stacktrace, you need to access to the views/index.gsp either remove or modify the line:

Remove the following line:

<li>Groovy version: ${org.codehaus.groovy.runtime.InvokerHelper.getVersion()}</li>

OR

Modify the following line:

<li>Groovy version: ${org.codehaus.groovy.runtime.InvokerHelper.getVersion()}</li>

to:

<li>Groovy version: ${GroovySystem.getVersion()}</li>