安装编译环境
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
下载安装源码tar包
建议下载到 /usr/local/src 目录下
wget http://nginx.org/download/nginx-1.11.1.tar.gz
tar zxvf nginx-1.11.1.tar.gz
编译源码
cd nginx-1.11.1
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
一般配置 例如:http://test.com/index.html
vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name test.com;
location / {
index index.php index.html index.htm;
}
}
二级目录配置 http://test.com/test/index.php
server {
listen 80;
server_name test.com;
location / {
index index.php index.html index.htm;
}
location /test/ {
if (!-e $request_filename) {undefined
rewrite ^/test/(.*)$ /test/index.php/$1 last;
break;
}
}
}
反向代理配置
upstream test{
server localhost:8002; // 可改成代理机器的端口
}
server {
listen 80;
server_name test.club www.test.club; ## 修改成自己的域名;
server_tokens off; ## Don't show the nginx version number, a security best practice
access_log /usr/local/nginx/logs/test.log; # 根据实际情况修改
error_log /usr/local/nginx/logs/test.log; # 根据实际情况修改
location / {
client_max_body_size 0;
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://test;
}
}