Nginx How to configure URLs

Source: Internet
Author: User
Tags file permissions tomcat

Name and version of the required software:

Pcre-8.02.tar.gz

Nginx-0.7.58.tar.gz

Nginx_upstream_hash-0.3.1.tar.gz

1. Installation Pcre

TAR-ZXVF pcre-8.02.tar.gz

CD pcre-8.02/

./configure

Make && make install

2. Install Url_hash patch for Nginx

TAR-ZXVF nginx-0.7.58.tar.gz

TAR-ZXVF nginx_upstream_hash-0.3.1.tar.gz

CD nginx-0.7.58/

Patch-p0 </var/tmp/loojoy/nginx_upstream_hash-0.3.1/nginx.patch

3. Installation Nginx

Groupadd www

Useradd www-g www

./configure--prefix=/usr/local/webserver/nginx

--user=www

--group=www

--add-module=/var/tmp/loojoy/nginx_upstream_hash-0.3.1

--with-http_ssl_module

--with-http_stub_status_module

4, check the nginx generated configuration file is correct

/usr/local/webserver/nginx/sbin/nginx-t

5, start Nginx

If the Nginx.conf check passes, start the nginx.

/usr/local/webserver/nginx/sbin/nginx

6. View Port 80

Netstat-ant

7, through the browser access:

http://your_nginx_server_ip/

If normal access is available, the Nginx installation succeeds.

8, modify the Nginx configuration file as follows:

-------------------Url_hash Forwarding Method nginx.conf--------------------

User www www

Worker_processes 10

Error_log Logs/error.log

#error_log Logs/error.log Notice

#error_log Logs/error.log Info

#pid Logs/nginx.pid

Worker_rlimit_nofile 51200

Events

{

Use Epoll

Worker_connections 51200

}

http

{

Include Mime.types

Default_type Application/octet-stream

Keepalive_timeout 120

Tcp_nodelay on

Upstream your.website.name{

Server your.tomcat.server.ip1:8080

Server your.tomcat.server.ip1:8080

Hash $request _uri

}

Server

{

Listen 80

server_name Your.website.name

Location/{

Proxy_pass Http://your.website.name

Proxy_set_header Host $host

Proxy_set_header X-real-ip $remote _addr

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for

}

Log_format www_gjw_com ' $remote _addr-$remote _user [$time _local] $request '

"$status" $body _bytes_sent "$http _referer"

"$http _user_agent" "$http _x_forwarded_for"

#access_log/data1/logs/www.log www_gjw_com

Location/nginx_status {

Stub_status on

Access_log off

}

}

}

-------------------[E]url_hash forwarding way nginx.conf[e]--------------------

9, add Nginx startup, shutdown, restart script

-------------------[S]url_hash forwarding nginx start, close script [S]--------------------

#!/bin/sh

cwd= ' pwd '

Case is in

Start

/usr/local/webserver/nginx/sbin/nginx

;

Stop

Kill-2 ' ps-ef|grep '/usr/local/webserver/nginx/sbin/nginx ' |grep-v ' grep ' |awk ' {print $} '

;

Restart)

CD "$CMD"

$ stop

$ start

;

*)

echo $ "Usage: $ {Start|stop|restart}"

Exit 1

Esac

Exit 0

-------------------[E]url_hash forwarding nginx start, close script [E]--------------------

Change the file permissions

chmod u+x nginx.sh

Launch Nginx./nginx.sh start

Reboot Nginx./nginx.sh restart

Close Nginx./nginx.sh stop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.