Linux和WindowXP上安装Nginx,以及简单配置
2017-04-13 17:47
786 查看
Linux下配置Nginx
环境:
环境:
1,Linux服务器 2,nginx-1.10.3.tar.gz http://nginx.org/en/download.html 3,openssl-1.0.2k.tar.gz https://www.openssl.org/ 4,pcre2-10.23.tar.gz http://www.pcre.org/ https://ftp.pcre.org/pub/pcre/ 5,zlib-1.2.11.tar.gz http://www.zlib.net/[/code]步骤: 讲讲我走的岔路吧,一开始看别人写的教程,他只说了安装pcre,我按照他的方法安装完后,去nginx目录下./configura 并不能成功。
后来只能把依赖全部安装上。具体如下:
1,安装openssl[root@localhost mrms]# tar -zxvf openssl-1.0.2k.tar.gz [root@localhost mrms]# cd openssl-1.0.2k [root@localhost openssl-1.0.2k]# ./config [root@localhost openssl-1.0.2k]# make [root@localhost openssl-1.0.2k]# make install
2, 安装zlib[root@localhost mrms]# tar -zxvf zlib-1.2.11.tar.gz [root@localhost mrms]# cd zlib-1.2.11 [root@localhost zlib-1.2.11]# ./configure [root@localhost zlib-1.2.11]# make [root@localhost zlib-1.2.11]# make install
3,安装pcre[root@localhost mrms]# tar -zxvf pcre-8.40.tar.gz [root@localhost mrms]# cd pcre-8.40 [root@localhost pcre-8.40]# ./configure [root@localhost pcre-8.40]# make [root@localhost pcre-8.40]# make install
4,安装nginx[root@localhost mrms]# tar -zxvf nginx-1.10.3.tar.gz [root@localhost mrms]# cd nginx-1.10.3 [root@localhost nginx-1.10.3]# ./configure --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2k [root@localhost nginx-1.10.3]# make [root@localhost nginx-1.10.3]# make install检测是否安装成功
cd /usr/local/nginx/sbin
./nginx -t
出现下图,说明安装成功。
启动nginx[root@localhost sbin]# ./nginx
查看端口[root@localhost sbin]# netstat -ntlp
修改文件conf/nginx.cnf 配置端口如下:
在浏览器中输入ip:7780
WindowsXP下,配置更简单
我下载的是 nginx-1.10.3.zip,地址是http://nginx.org/en/download.html
解压得到如下文件
修改conf/nginx.cnf文件如下添加集群#服务器的集群 upstream cast.com { #服务器集群名字 server 192.168.0.65:18080 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。 server 192.168.0.65:8888 weight=2; server 192.168.0.7:9090 weight=3; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} location / { proxy_pass http://cast.com; proxy_redirect default; }注意集群名的地方要一致。
启动Nginx;start nginx.exe
然后在浏览器中输入地址 http://localhost 就可以了。
完毕!
------------------------------------------------------------分割线--------------------------------------------------------------------------------
有不对的地方还希望指正,谢谢!
下面列份配置
#user nobody;
worker_processes 2;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 10240;
events {
worker_connections 10240;
}
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;
#gzip on;
#upstream mysrv {
# server 127.0.0.1:9091;
# server 127.0.0.1:9092 backup; #热备
#}
upstream mysrv {
server 127.0.0.1:9091;
server 127.0.0.1:9092 backup; #热备
}
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
#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 / {
proxy_pass http://mysrv; proxy_redirect default;
}
# 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;
# }
#}
}
相关文章推荐
- Linux下载安装Nginx并配置,以及启动/停止/重启命令
- Linux 下Nginx 的安装及负载均衡的简单配置
- linux如何安装nginx以及配置多域名对多端口
- linux下安装nginx并简单配置,利用tomcat-redis共享session
- Nginx安装以及简单配置
- Linux下安装配置Nginx以及安装PHP
- Linux 下Nginx 的安装及负载均衡的简单配置
- Linux上go的安装配置以及简单使用
- Nginx在Linux下的安装与配置,以及遇到问题的解决整理
- 最简单!阿里云服务器采用 LNMP一键安装包 配置 Linux+Nginx+Mysql+PHP
- linux系统上nginx安装及简单的反向代理配置
- Linux(Centos)之安装Nginx及注意事项 阅读目录 1.Nginx的简单说明 2.准备工作 3.安装SSL功能需要openssl库以及gzip模块需要的zlib库 4.安装 rewri
- Nginx简单介绍以及安装与配置
- Nginx的编译安装以及简单配置
- nginx 系列1 linux下安装以及配置IIS分发
- Linux下源码安装nginx服务器以及部分配置
- LINUX——关于nginx的安装配置以及如何简易的使用
- Linux 下Nginx 的安装及负载均衡的简单配置
- liunx系统安装nginx,以及配置、用到的简单指令
- Nginx安装配置,简单构建LNMP环境配置反向代理,实现动静分离,以及实现负载均衡。