install nginx18"/>
ubantu16 install nginx18
安装必备包
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install libtool
下载安装
wget .18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0./configure --prefix=/usr/local/nginx --with-http_ssl_module
sudo make
sudo make install
nginx.sh脚本
#!/bin/bash
#
# Simple nginx init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.### BEGIN INIT INFO
# Provides: nginx_80
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Nginx data structure server
# Description: Nginx data structure server. See .html
### END INIT INFOset -e
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
CONF=/opt/app/config/nginx.conf# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0d_start() {$DAEMON -c $CONF || echo -n " already running"
}d_stop() {$DAEMON -s quit || echo -n " not running"
}d_reload() {$DAEMON -s reload || echo -n " could not reload"
}case "$1" instart)echo -n "Starting $DESC: $NAME"d_startecho ".";;
stop)echo -n "Stopping $DESC: $NAME"d_stopecho ".";;
reload)echo -n "Reloading $DESC configuration..."d_reloadecho "reloaded.";;
restart)echo -n "Restarting $DESC: $NAME"d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.sleep 2d_startecho ".";;
*)echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2exit 3;;
esac
exit 0
配置
cp /usr/local/nginx/conf/nginx.conf /opt/app/config/sudo vim /etc/init.d/nginx
#超考上边脚本nginx
chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
启动
sudo service nginx start
sudo service nginx restart
sudo service nginx status
sudo service nginx stop
原始命令操作
sudo /usr/local/nginx/sbin/nginx -c /opt/app/config/nginx.conf
#或者
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
配置代理
location / {proxy_pass http://192.168.0.1/project/;proxy_cookie_path /project/ /;proxy_http_version 1.1;proxy_set_header Host $proxy_host;proxy_set_header Real-Host $host; #保留真实域名proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#设置下面两行即可(websock参透)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
针对大文件配置
proxy_send_timeout 90;
proxy_read_timeout 1800;
client_max_body_size 2048m;
#proxy_connect_timeout :后端服务器连接的超时时间_发起握手等候响应超时时间
#proxy_read_timeout:连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理(也可以说是后端服务器处理请求的时间)
#proxy_send_timeout :后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据
压缩
# gzip configgzip on;gzip_min_length 1k;gzip_comp_level 9;gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;gzip_vary on;gzip_disable "MSIE [1-6]\.";
config配置
server {listen 80;server_name 你的域名;#后台服务配置,配置了这个location便可以通过http://域名/project/xxxx 访问 location ^~ /project {proxy_pass http://127.0.0.1:8080/project/;proxy_set_header Host 127.0.0.1;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}#解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题location / {root html;index index.html index.htm;if (!-e $request_filename) {rewrite ^(.*)$ /index.html?s=$1 last;break;}}}
更多推荐
ubantu16 install nginx18
发布评论