nginx服务器配置
来源:互联网 发布:淘宝信誉提升 编辑:程序博客网 时间:2024/05/01 15:33
nginx服务器配置
近期准备开始学习做安卓的直播品台,后几期的博文都会围绕直播平台来写,记录所踩的坑。本文介绍安装和部署nginx服务器,以及nginx处理前端请求处理跨域的问题
- Windows安装nginx
下载地址 nginx官网
下载过程中选择最新版本的Stable version这是官方的稳定版本,Mainline version是官方的测试版本,应该是添加了新功能之类的。 安装和配置nginx
下载下来是一个压缩文件,另一个pgp的文件不是直接的下载方式,直接点 nginx/Windows-1.10.3 这个下载就行了,版本不同,此时最高版本是1.10.3。
解压后文件为打开最下面的nginx.exe运行即可,此时nginx服务器已经打开。默认的端口是80,如果没有端口冲突的话在浏览器打开 http://localhost/ 就可以看到如下画面
说明nginx服务器启动成功,如果失败了自己可以打开logs目录下的error.log看看哪里出错了。
接下来说说配置文件的内容
打开conf目录下的nginx.conf,这是nginx的配置文件,可以使用记事本打开,但是记事本打开有个问题就是保存后可能会因为编码问题导致内容格式不正确,所以建议用其他编辑器打开,调至utf-8的编码格式编辑。
先看一下我的配置文件
#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; #配置IIS的IP地址和访问端口 upstream iis { server 192.168.1.188:8088; } server { listen 8089; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; #add_header Access-Control-Allow-Origin *; #add_header Access-Control-Allow-Headers X-Requested-With; #add_header Access-Control-Allow-Methods GET,POST,OPTIONS; } #Nginx代理配置 location /iis/ { proxy_pass http://iis/; } location /html { alias E:\projects\test\app\src\main\res\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 ~ \.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; # } #}}
# 代表注释主要是修改http中间的内容这个配置文件主要大致意思是监听 8089端口,代理 192.168.1.188:8088 路径服务器目录为/ 当前目录,初始页为index.html
一般服务器的目录和我们项目目录可能不在用一个地方,这时候可以修改
location / { root html; index index.html index.htm; }
修改成
location / { root E:/**/**/**/**/; index index.html index.htm; }
这时候初始页就是当前E盘的目录下了,注意一个问题,复制目录路径的时候有可能是E:\**\**\**\**\
这样的话有可能会报错,注意一下。
这样有关nginx的服务器就配置完成了。要了解更多查看官方文档吧。
有关nginx的代理和处理前端请求跨域的问题我们下一小节再讲。
0 0
- 配置Nginx服务器虚拟目录
- nginx服务器的配置
- Nginx缓存服务器配置
- nginx配置图片服务器
- nginx服务器配置
- Nginx配置https服务器
- nginx 配置HTTPS服务器
- nginx配置图片服务器
- Nginx服务器配置指令
- Nginx服务器基本配置
- Nginx配置服务器SSI
- nginx服务器配置详解
- nginx服务器的配置
- 服务器nginx+nodejs配置
- nginx配置https服务器
- nginx服务器配置
- 【服务器】nginx二级域名配置
- nginx配置web服务器
- qt最小化托盘失焦问题
- 算法
- android Canvas 和 Paint用法
- VS2008串口测试程序
- 如何利用SVN的Branches与Tags进行版本的管理
- nginx服务器配置
- IO阻塞和NIO非阻塞的理解
- Qt 中QFileDialog的使用
- UVa 12665
- elk(1)-趁离职总结下我前公司elk方案
- leetcode解题之 Combination Sum java 版(组合求和)
- Docker下centos6 + mha全记录
- SpringMVC和Mybatis的整合
- 简单读取dataSource.properties配置文件