您的位置:首页 > 运维架构 > Nginx

Nginx 安装与端口分发

2016-10-25 00:00 148 查看
一:安装

刚开始安装,尝试用yum命令,按照http://blog.csdn.net/netinnet/article/details/8205368的教程,发现系统总是报configure: error: * ln doesn’t support –relative *的错误,google 了一下,感觉修复起来挺麻烦,于是继续找教程,按照如下教程http://magic3.blog.51cto.com/1146917/773408将Nginx安装成功。

1、安装 pcre(下载地址http://www.pcre.org

tar -zxvf pcre-8.02.tar.gz

./configure

make

make install

./configure 过程中可能会出现“You need a C++ compiler for C++ support.”的错误,这时候可以执行命令

“yum install -y gcc gcc-c++”

默认安装到/usr/local/lib下即可。

安装过程中可能会报.libs/pcrecpp.o:could not read symbols: Bad value的错误,解决办法参考

http://blog.csdn.net/jiajiano6/article/details/10929773,执行./configure –disable-shared –with-pic 命令,再进行make&&make install 命令

2、安装nginx (下载地址:http://nginx.org/en/download.html

tar zxvf nginx-1.0.11.tar.gz

cd nginx-1.0.11

./configure –prefix=/usr/local/nginx –with-poll_module –with-http_stub_status_module –with-http_ssl_module

make && make install

3)管理nginx服务

启动:

/usr/local/nginx/sbin/nginx

停止

/usr/local/nginx/sbin/nginx -s stop

重启

/usr/local/nginx/sbin/nginx -s reload

注意:启动nginx的时候,会报 libpcre.so.1: cannot open shared object file: No such file or directory 的错误。解决方法是http://blog.csdn.net/lixuekun820/article/details/39205703教程中所说:将 libapr-1.so.0 copy 从/usr/local/lib 拷贝到 /usr/lib/ 或 /usr/lib64/下即可。如果找不到libapr-1.so.0 这个文件,也可以按照http://blog.csdn.net/hongweigg/article/details/17469929的方法,执行ln -s /usr/local/lib/libpcre.so.1 /lib64

二:端口分发配置

在阿里云服务器上我们用express系统安装了公司的官网,监听8888端口。同时又安装了几个tomcat,用于我们的微信商城。监听的是9080端口。注意由于微信只接受80端口的url地址。所以我们需要一个子域名指向微信商城。具体配置如下在Nginx文件夹的conf/nginx.conf 文件中。

server{
listen  80;
server_name smartisan.cn;
location /{
proxy_pass http://127.0.0.1:8888; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server{
listen 80;
server_name mall.smartisan.cn;
location /{
proxy_pass  http://127.0.0.1:9080; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
76%
}
}.


总结:Nginx 很强大
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx