前端时间做了两个微信项目,部署在同一个服务器上了。由于需要和微信对接,都需要用到80端口,所以就用Nginx配置了一个反向代理服务器。折腾了一下午,下面把配置的步骤和信息分享出来供大家参考。
获取Nginx
可以在Nginx官方网站(http://nginx.org/en/download.html)获取Nginx源码包。
CHANGES | nginx-1.7.4 pgp |
第一步:解压
tar -zxvf nginx-1.7.4.tar.gz
第二步:进入nginx-1.7.4,执行./configure 命令
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ [root@localhost nginx-1.7.4]# ./configure
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
出现这个错误。
那么就是gcc 包没有安装。安装gcc 吧,骚年。
yum -y install gcc
--------------------------------------------------------------------------
再次执行./configure
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
yum install pcre-devel
------------------------------------------------------
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
-------------------------------------------
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
开启ssl 模块 执行./configure --with-http_ssl_module
启用“server+status"页,执行./configure --with-http_stub_status_module
两个都启动,不用我说了。执行./configure --with-http_stub_status_module --with-http_ssl_module
-------------------------------------------
-------------------------------------------
执行make 命令
执行make install 命令
至此,nginx 执行成功了-------------------------------------------
export PATH=$PATH:$NGINX_HOME/sbin
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
//同一个域名配置一个server就行
server {
listen 80; //监听服务器的80端口
server_name www.jianchibang.org; //服务器的域名
proxy_set_header Host $host; //
root /insistOn/weixin_web/user;
#charset koi8-r;
#access_log logs/host.access.log main;
//配置俩个项目路径
location /insistOn {
proxy_pass http://115.28.138.106:8080/insistOn;
proxy_redirect default;
}
location / {
proxy_pass http://115.28.138.106:8081/;
proxy_redirect default;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#server {
# listen 80;
# server_name www.jianchibang.org;
# proxy_set_header Host $host;
# location / {
# proxy_pass http://115.28.138.106:8081/;
# proxy_redirect default;
# }
#}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}