ubuntu中使用Nginx配置Mapserver(宝塔面板中安装mapserver)
前言
对于一部分开发者和轻量级环境而言,Nginx无疑有很多优势,很可能我们已有的环境是Lnmp环境(Nginx + mysql + php)。如果你已有的Lnmp环境下已经部署了内容。现在又想添加mapserver,有和我一样对服务器环境部署不是那么熟悉,可能会遇到一个很头疼的问题——整个中文互联网就没有个靠谱的NGINX + Mapserver部署教程。
这里我折腾了很久解决了,在此将方法分享在这里帮助有同样问题的伙伴们解决。
一、安装配置 mapserver
1、安装mapserver
先决条件你已经安装了 Lnmp环境。
终端输入:
sudo apt-get install mapserver-bin mapserver-doc
注:因为 UbuntuGIS库的存在,这里安装时相关库会自动安装。
2、使用spawn-fcgi将Mapserver配置为CGI Worker
如果尚未安装,请安装spawn-fcgi。
sudo apt-get install spawn-fcgi
FastCGI配置
将mapserver作为cgi服务运行。以超级用户权限在/etc/init.d/mapserv中创建文件。放入此内容并保存。
> sudo touch /etc/init.d/mapserv
> cd /etc/init.d/
> ls
查看是否已经生成()
添加下面内容到mapserv
#!/usr/bin/env sh
#
# description: Mapserver Service Manager
# processname: lt-mapserv
# pidfile: /var/run/mapserv.pid
# Source function library.
#. /etc/init.d/functions
# Check that networking is up.
#. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
PREFIX=/usr
NAME=mapserv
PID=/var/run/mapserv.pid
DAEMON=$PREFIX/bin/spawn-fcgi
DAEMON_OPTS=" -a 127.0.0.1 -p 9999 -F 4 -u www-data -U www-data -P $PID $PREFIX/bin/mapserv"
start () {
echo -n $"Starting $NAME "
exec $DAEMON $DAEMON_OPTS >> /dev/null
daemon --pidfile $PID
RETVAL=$?
echo
[ $RETVAL -eq 0 ]
}
stop () {
echo -n $"Stopping $NAME "
killproc -p $PID
#make sure all mapservers are closed
pkill -f lt-mapserv
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f $PID
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status lt-mapserv
RETVAL=$?
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
RETVAL=2
;;
esac
exit $RETVAL
向文件添加执行权限。
> sudo chmod +x /etc/init.d/mapserv
使用命令启动mapserver服务
> sudo /etc/init.d/mapserv start
修改Nginx配置文件(这里以宝塔面板环境为例):
在配置中添加
location / {
# Load from /etc/init.d/mapserv
fastcgi_pass 127.0.0.1:9999;
include fastcgi_params;
fastcgi_param SCRIPT_NAME /usr/bin/mapserv$fastcgi_script_name;
}
修改/www/server/nginx/conf/nginx.conf(宝塔面板双击编辑)
修改后:
user www www;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
#include luawaf.conf;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server {
listen 80;
listen [::]:80;
server_name mapserver.local;
add_header Access-Control-Allow-Origin *;
location / {
# Load from /etc/init.d/mapserv
fastcgi_pass 127.0.0.1:9999;
include fastcgi_params;
fastcgi_param SCRIPT_NAME /usr/bin/mapserv$fastcgi_script_name;
}
}
server
{
listen 888;
server_name phpmyadmin;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /www/wwwlogs/access.log;
}
include /www/server/panel/vhost/nginx/*.conf;
}
二、测试设否配置成功
怎么看mapserver是否配置成功
在局域网下的浏览器中打开如下链接:
http://替换自己 IP /?
注意:不是
http://替换自己 IP /cgi-bin/mapserv?
如果返回结果为如下:
No query information to decode. QUERY_STRING is set, but empty.
说明你的mapserver配置成功。大功告成!!!!