博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx的安装和配置
阅读量:6941 次
发布时间:2019-06-27

本文共 4518 字,大约阅读时间需要 15 分钟。

1.安装说明:

系统环境:Ubuntu 14.04.3 LTS

软件:nginx-1.8.0.tar.gz

安装位置:/opt/nginx

 

2.安装

需要用到的安装包:

openssl-fips-2.0.10.tar.gz

zlib-1.2.8.tar.gz

pcre-8.37.tar.gz

nginx-1.8.0.tar.gz

安装顺序依次为:opensslzlibpcre, 然后安装Nginx

 

2.1安装openssl-fips-2.0.2.tar.gz

tar –zxvf openssl-fips-2.0.10.tar.gz

cd openssl-fips-2.0.10

./config

make

make install

2.2 安装zlib-1.2.8.tar.gz

tar –zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure

make

make install

2.3安装pcre-8.37.tar.gz (需安装编译c++环境: apt-get install build-essential)

在安装pcre-8.37.tar.gz之前需要安装c++编译环境,否则在执行./configure时会报错。

apt-get install build-essential

 

tar –zxvf pcre-8.37.tar.gz

cd pcre-8.37

./configure

make

make install

2.4安装nginx-1.8.0.tar.gz

tar -zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0

./configure --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-fips-2.0.10

make

make install

至此Nginx的安装完成!

检测nginx是否安装成功

cd /usr/local/nginx/sbin

./nginx –t

出现如下所示提示,表示安装成功

root :/usr/local/nginx/sbin# ./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

启动nginx

./ngixn

查看端口:

netstat -tnlp  | grep nginx

root :/usr/local/nginx/sbin# netstat -tnlp | grep nginx

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2957/nginx

并且通过浏览器访问

3.nginx负载均衡配置

打开 /usr/local/nginx/conf/nginx.conf 配置文件,做如下配置即可:

user  root root;worker_processes  1; #error_log  logs/error.log;#error_log  logs/error.log  notice;error_log  logs/error.log  warn; 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;     #设定负载均衡的服务器列表    upstream myserver{     server 192.168.1.171:8080;                 server 192.168.1.172:8080;                 server 192.168.1.173:8080;    }     #侦听服务器信息    server {        listen       80;        server_name  192.168.1.110;               #charset koi8-r;         #access_log  logs/host.access.log  main;         location / {                         #root   html;                         #index  index.html index.htm;                         proxy_pass http://myserver;                         proxy_redirect off;                         proxy_set_header Host $host;                         proxy_set_header X-Real-IP $remote_addr;                         #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP                         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        }         #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;        #}    }      # 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;    #    }    #} }

转载于:https://my.oschina.net/wcyong/blog/511618

你可能感兴趣的文章
Ubuntu下MySQL5.7配置字符集utf8和sql_mode
查看>>
最近几天玩lxc的经历
查看>>
EXCEL2010粘贴复制技巧
查看>>
Network security CA Server
查看>>
ASP.NET MVC Model元数据(一)
查看>>
GIT分支管理是一门艺术
查看>>
android listview item点击后,显示点击效果
查看>>
Http服务器-第六步解析URL的UTF8编码
查看>>
Oracle Shared pool内存管理图解
查看>>
为什么Flashback Log产生量要远少于Redo Log?
查看>>
我的友情链接
查看>>
Mysqlhotcopy热备本工具介绍
查看>>
ubuntu1204 source list
查看>>
Stylish 样式
查看>>
各种大型网站技术架构
查看>>
MySQL + MHA + keepalive + VIP 高可用实验
查看>>
exchange2010 移动邮箱
查看>>
使用syslog-ng搭建日志服务器
查看>>
跨域 Cookie 实现单点登录
查看>>
Facade模式[fəˈsɑːd]
查看>>