手记系列之三 ----- 关于使用Nginx的一些使用方法和经验( 三 )


Nginx监听多端口以及Https多端口,就是两端server
https则需要配置证书
server {#listen8181;#server_name192.168.0.1#charset koi8-r;#access_loglogs/host.access.logmain;#rewrite ^(.*)$ https://$host$1 permanent;}# HTTPS server#server {listen8080 ssl;server_name192.168.0.1 ;ssl_certificate/usr/local/nginx/cert/xxx.crt;ssl_certificate_key/usr/local/nginx/cert/xxx.key;ssl_session_cacheshared:SSL:1m;ssl_session_timeout30m;#ssl_ciphersHIGH:!aNULL:!MD5;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_cipherson;location / {root/home/release/dist;indexindex.html index.htm;}location ^~ /api/ {proxy_pass http://127.0.0.1:9999;proxy_cookie_path / /;proxy_pass_header Set-Cookie;proxy_set_header Host zans;}proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}# HTTPS server#server {listen443 ssl;server_namexxx.com ;ssl_certificate/usr/local/nginx/cert/xxx.crt;ssl_certificate_key/usr/local/nginx/cert/xxx.key;ssl_session_cacheshared:SSL:1m;ssl_session_timeout30m;#ssl_ciphersHIGH:!aNULL:!MD5;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_cipherson;location / {root/home/release/app;indexindex.html index.htm;}location ^~ /api {proxy_pass http://127.0.0.1:6666;proxy_cookie_path / /;proxy_pass_header Set-Cookie;proxy_set_header Host zans;}proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}错误处理1 , Nginx: error while loading shared libraries: libpcre.so.1
则说明未安装pcre或安装了未设置软链,安装或者设置器软链即可
ln -s /usr/local/lib/libpcre.so.1 /lib64/2 , 实现负载均衡之后 , 页面无法跳转
原因: nginx 默认的端口是80,更改监听的端口之后 , 也需要更改一下 。
也会出现这种错误:net::ERR_NAME_NOT_RESOLVED
解决办法:在location 下添加proxy_set_header Host$host:port 这个配置,port 和listen 的端口保持一致, 不然是无法跳转的 。
3 , 使用文件服务器的一些问题

  1. nginx需要设置传输的大小;
  2. 【手记系列之三 ----- 关于使用Nginx的一些使用方法和经验】访问若出现了403权限问题,一般情况下是上传的图片用root创建的,但nginx访问使用nginx用户访问的,所以在linux系统出现了问题 。解决办法一:nginx使用root用户启动,在nginx的配置改成 use root;解决办法二:全局设置文件夹的权限 , 并且使nginx拥有读取的权限;
  3. nginx限速问题 , 如果宽带不高,可以对大图片文件进行限速 。
其他之前写的nginx

推荐阅读