首先是安装nginx,环境依然是ubuntu12.04(64位),通过下面命令:
sudo apt-get install nginx
安装好之后就是启动,目前我知道的在ubuntu下有两种启动方式:
sudo /etc/init.d/nginx start #通过init.d下的启动文件启动。
sudo service nginx start #通过ubuntu的服务管理器启动
在浏览器中输入http://localhost,看看是不是出现“Welcome to nginx!”的页面。如果没有的话,先继续往下看配置。
在我的系统中nginx的配置文件在/etc/nginx下。
打开nginx.conf文件,配置如下:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 3600;
client_header_timeout 3600;
client_body_timeout 3600;
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
types_hash_max_size 2048;
client_max_body_size 36G;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# Mccts-start
server {
listen 2333;
server_name localhost;
root /home/mccts/start;
index index.html index.htm;
location / {
# 截取404的uri,传给 @router
try_files $uri $uri/ @router;
}
location @router {
# 接到截取的uri 并按一定规则重写uri和vue路由跳转
rewrite ^.*$ /index.html last;
}
}
# McctsControl
server {
listen 9527;
server_name localhost;
autoindex on;
root /home/mccts/mccts-control/web;
index index.html index.htm;
location / {
# 截取404的uri,传给 @route
try_files $uri $uri/ @router;
}
location /control/ {
proxy_pass http://127.0.0.1:8080/;
#proxy_pass http://192.168.1.28:8080/;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /analysis/ {
proxy_pass http://127.0.0.1:8081/;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /Rocket/ {
proxy_pass http://127.0.0.1:3101/Rocket/;
}
location @router {
# 接到截取的uri 并按一定规则重写uri和vue路由跳转
rewrite ^.*$ /index.html last;
}
}
# McctsAnalysis
server {
listen 9528;
server_name localhost;
root /home/mccts/mccts-analysis/web;
index index.html index.htm;
location / {
# 截取404的uri,传给 @route
try_files $uri $uri/ @router;
}
location /analysis {
proxy_pass http://127.0.0.1:8081/;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# McctsObject
server {
listen 9529;
server_name localhost;
root /home/mccts/mccts-object/web;
index index.html index.htm;
location / {
# 截取404的uri,传给 @route
try_files $uri $uri/ @router;
}
location /object {
proxy_pass http://127.0.0.1:8083/;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location @router {
# 接到截取的uri 并按一定规则重写uri和vue路由跳转
rewrite ^.*$ /index.html last;
}
}
# McctsBallistic
server {
listen 3101;
server_name localhost;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
add_header 'Access-Control-Allow-Headers' 'Content-Type';
if ($request_method = 'OPTIONS') {
return 200;
}
location /Rocket/ {
proxy_pass http://127.0.0.1/Rocket/;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
#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;
# server {
# listen 80;
# server_name localhost;
# add_header Access-Control-Allow-Origin '*' always;
# #charset koi8-r;
# #access_log logs/host.access.log main;
# location / {
# root html/emulate2/publish;
# # index index.html index.htm;
# }
# }
server {
listen 8080;
server_name localhost;
add_header 'Access-Control-Allow-Origin' '*';
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/Cesium/;
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;
#}
}
server {
listen 4444;
server_name localhost;
add_header Access-Control-Allow-Origin '*' always;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root C:/MapDownload/mapabc/satellite;
root html/satellite;
autoindex on;
# index index.html index.htm;
}
}
server {
listen 3200;
server_name _;
# add_header Access-Control-Allow-Origin '*' always;
# add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
# add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept';
# if ($request_method = 'OPTIONS') {
# return 204;
# }
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# proxy_pass http://127.0.0.1:8765/;
# proxy_redirect default;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root html/Emulate;
autoindex on;
# index index.html index.htm;
}
}
# server {
# listen 8765;
# server_name localhost;
# add_header Access-Control-Allow-Origin '*' always;
# add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
# add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept';
# #charset koi8-r;
# #access_log logs/host.access.log main;
# location / {
# proxy_pass http://127.0.0.1:8001/;
# }
# }
# 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;
# }
#}
}
这样就ok了,重启你的nginx:
sudo service nginx restart
.
接着你直接访问 http://127.0.0.1就可以访问