备注:做完映射后,输入IP(URL)即可,不用输入端口,走默认80端口
第一步:
cd /etc/nginx/sites-enabled
第二步:
查看是否有文件 default(该文件可以为其他,根据需要命名)
ls
第三步:
编辑 default 文件
# 以下是在一个 server 中
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
client_max_body_size 100M;
client_body_buffer_size 128k;
#
# add_header 'Access-Control-Allow-Origin' '*';
# add_header 'Access-Control-Allow-Methods'
'GET,POST,OPTIONS,PUT,HEAD,PATCH,DELETE';
proxy_pass http://127.0.0.1:12000;
}
二、整个NGINX配置的样例
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
if ( $request_method = OPTIONS ) {
return 200 '';
}
# 允许跨越
add_header "Access-Control-Allow-Origin" "*";
# 允许的请求方法
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, PUT, HEAD, PATCH, DELETE";
# 头部中允许的参数
add_header "Access-Control-Allow-Headers" "Content-Type, Authorization, X-Requested-With, Session-Id";
# 映射的 12000 端口开的服务
location / {
client_max_body_size 100M;
client_body_buffer_size 128k;
proxy_pass http://127.0.0.1:12000;
}
# 映射的 8000 并且 URL 以 /api 开始的路由
location /api {
client_max_body_size 100M;
client_body_buffer_size 128k;
proxy_pass http://127.0.0.1:8000;
nginx基础配置
nginx